Guest User

Untitled

a guest
Jun 3rd, 2025
17
0
316 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Drupal\my_custom_module\Plugin\EmbeddedContent;
  4.  
  5. use Drupal\Core\Form\FormStateInterface;
  6. use Drupal\Core\StringTranslation\StringTranslationTrait;
  7. use Drupal\embedded_content\EmbeddedContentInterface;
  8. use Drupal\embedded_content\EmbeddedContentPluginBase;
  9.  
  10. /**
  11.  * Arrow Link plugin.
  12.  *
  13.  * @EmbeddedContent(
  14.  *   id = "arrow_link",
  15.  *   label = @Translation("Arrow Link"),
  16.  *   description = @Translation("Renders a link as arrow link."),
  17.  * )
  18.  */
  19. class ArrowLink extends EmbeddedContentPluginBase implements EmbeddedContentInterface {
  20.  
  21.   use StringTranslationTrait;
  22.  
  23.   /**
  24.    * {@inheritdoc}
  25.    */
  26.   public function defaultConfiguration() {
  27.     return [
  28.       'url' => NULL,
  29.       'title' => NULL,
  30.       'display_arrow' => 1,
  31.     ];
  32.   }
  33.  
  34.   /**
  35.    * {@inheritdoc}
  36.    */
  37.   public function build(): array {
  38.     return [
  39.       '#type' => 'component',
  40.       '#component' => 'THEME_NAME:arrow-link',
  41.       '#props' => [
  42.         'title' => $this->configuration['title'],
  43.         'url' => $this->configuration['url'],
  44.         'display_arrow' => $this->configuration['display_arrow'],
  45.       ],
  46.     ];
  47.   }
  48.  
  49.   /**
  50.    * {@inheritdoc}
  51.    */
  52.   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  53.     $form['url'] = [
  54.       '#type' => 'url',
  55.       '#title' => $this->t('URL'),
  56.       '#default_value' => $this->configuration['url'],
  57.       '#required' => TRUE,
  58.     ];
  59.  
  60.     $form['title'] = [
  61.       '#type' => 'textfield',
  62.       '#title' => $this->t('Title'),
  63.       '#default_value' => $this->configuration['title'],
  64.       '#required' => TRUE,
  65.     ];
  66.  
  67.     $form['display_arrow'] = [
  68.       '#type' => 'checkbox',
  69.       '#title' => $this->t('Display arrow'),
  70.       '#default_value' => (bool) $this->configuration['display_arrow'],
  71.     ];
  72.  
  73.     return $form;
  74.   }
  75.  
  76.   /**
  77.    * {@inheritdoc}
  78.    */
  79.   public function isInline(): bool {
  80.     return TRUE;
  81.   }
  82.  
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment