Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Drupal\my_custom_module\Plugin\EmbeddedContent;
- use Drupal\Core\Form\FormStateInterface;
- use Drupal\Core\StringTranslation\StringTranslationTrait;
- use Drupal\embedded_content\EmbeddedContentInterface;
- use Drupal\embedded_content\EmbeddedContentPluginBase;
- /**
- * Arrow Link plugin.
- *
- * @EmbeddedContent(
- * id = "arrow_link",
- * label = @Translation("Arrow Link"),
- * description = @Translation("Renders a link as arrow link."),
- * )
- */
- class ArrowLink extends EmbeddedContentPluginBase implements EmbeddedContentInterface {
- use StringTranslationTrait;
- /**
- * {@inheritdoc}
- */
- public function defaultConfiguration() {
- return [
- 'url' => NULL,
- 'title' => NULL,
- 'display_arrow' => 1,
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function build(): array {
- return [
- '#type' => 'component',
- '#component' => 'THEME_NAME:arrow-link',
- '#props' => [
- 'title' => $this->configuration['title'],
- 'url' => $this->configuration['url'],
- 'display_arrow' => $this->configuration['display_arrow'],
- ],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
- $form['url'] = [
- '#type' => 'url',
- '#title' => $this->t('URL'),
- '#default_value' => $this->configuration['url'],
- '#required' => TRUE,
- ];
- $form['title'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Title'),
- '#default_value' => $this->configuration['title'],
- '#required' => TRUE,
- ];
- $form['display_arrow'] = [
- '#type' => 'checkbox',
- '#title' => $this->t('Display arrow'),
- '#default_value' => (bool) $this->configuration['display_arrow'],
- ];
- return $form;
- }
- /**
- * {@inheritdoc}
- */
- public function isInline(): bool {
- return TRUE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment