index.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Blocks; |
| 4 | |
| 5 | use IlluminateAgnostic\Arr\Support\Arr; |
| 6 | use Kubio\Core\Blocks\BlockBase; |
| 7 | use Kubio\Core\Registry; |
| 8 | use Kubio\Core\Utils; |
| 9 | |
| 10 | |
| 11 | class SocialIconsBlock extends BlockBase { |
| 12 | const OUTER = 'outer'; |
| 13 | |
| 14 | public function __construct( $block, $autoload = true ) { |
| 15 | parent::__construct( $block, $autoload ); |
| 16 | } |
| 17 | |
| 18 | public function mapPropsToElements() { |
| 19 | return array( |
| 20 | self::OUTER => array(), |
| 21 | ); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | Registry::registerBlock( __DIR__, SocialIconsBlock::class ); |
| 26 | |
| 27 | class SocialIconBlock extends BlockBase { |
| 28 | const LINK = 'link'; |
| 29 | const ICON = 'icon'; |
| 30 | |
| 31 | public function mapPropsToElements() { |
| 32 | $link = $this->getAttribute( 'link' ); |
| 33 | $link_attributes = Utils::getLinkAttributes( $link ); |
| 34 | |
| 35 | $icon_name = $this->getAttribute( 'icon.name' ); |
| 36 | |
| 37 | return array( |
| 38 | self::LINK => array_merge( |
| 39 | $link_attributes, |
| 40 | array( |
| 41 | 'aria-label' => esc_attr( |
| 42 | sprintf( |
| 43 | // translators: %s: social link value |
| 44 | __( 'Social link: %s', 'kubio' ), |
| 45 | Arr::get( $link, 'value', '' ) |
| 46 | ) |
| 47 | ), |
| 48 | ) |
| 49 | ), |
| 50 | |
| 51 | self::ICON => array( |
| 52 | 'name' => $icon_name, |
| 53 | ), |
| 54 | ); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | Registry::registerBlock( |
| 59 | __DIR__, |
| 60 | SocialIconBlock::class, |
| 61 | array( |
| 62 | 'metadata' => './blocks/social-icon/block.json', |
| 63 | ) |
| 64 | ); |
| 65 |