Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
<?php

/**
 * @file
 * Contains \Drupal\dds_content\Plugin\Linkit\Attribute\Title.
 */

namespace Drupal\dds_content\Plugin\Linkit\Attribute;

use Drupal\Core\Form\FormStateInterface;
use Drupal\linkit\ConfigurableAttributeBase;

/**
 * Title attribute.
 *
 * @Attribute(
 *   id = "dds_link_title",
 *   label = @Translation("DDS Link Title"),
 *   html_name = "title",
 *   description = @Translation("Basic input field for the title attribute.")
 * )
 */
class Title extends ConfigurableAttributeBase {

  /**
   * {@inheritdoc}
   */
  public function buildFormElement($default_value) {
    $element = [
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#description' => $this->t('To improve site usability, it is recommended to supply a descriptive text for those using screenreader to use your website.'),
      '#default_value' => $default_value,
      '#maxlength' => 255,
      '#size' => 40,
    ];

    if ($this->configuration['automatic_title']) {
      $element['#attached']['library'][] = 'dds_content/linkit_attribute.title';
      $element['#description'] .= '<br><em>';
      $element['#description'] .= $this->t('For internal pages this gets auto populated once a link as been selected via the content search function.');
      $element['#description'] .= '</em>';
    }

    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      'automatic_title' => TRUE,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['automatic_title'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Automatically populate title'),
      '#default_value' => $this->configuration['automatic_title'],
      '#description' => $this->t('Automatically populate the title attribute with the title from the match selection.'),
    ];

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configuration['automatic_title'] = $form_state->getValue('automatic_title');
  }

}