defaultSettings example


class LinkWidget extends WidgetBase {

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'placeholder_url' => '',
      'placeholder_title' => '',
    ] + parent::defaultSettings();
  }

  /** * Gets the URI without the 'internal:' or 'entity:' scheme. * * The following two forms of URIs are transformed: * - 'entity:' URIs: to entity autocomplete ("label (entity id)") strings; * - 'internal:' URIs: the scheme is stripped. * * This method is the inverse of ::getUserEnteredStringAsUri(). * * @param string $uri * The URI to get the displayable string for. * * @return string * * @see static::getUserEnteredStringAsUri() */

class StringTextareaWidget extends WidgetBase {

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'rows' => '5',
      'placeholder' => '',
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element['rows'] = [
      '#type' => 'number',
      '#title' => $this->t('Rows'),
      '#default_value' => $this->getSetting('rows'),
      '#required' => TRUE,
      

class EntityReferenceLabelFormatter extends EntityReferenceFormatterBase {

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

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $elements['link'] = [
      '#title' => $this->t('Link label to the referenced entity'),
      '#type' => 'checkbox',
      '#default_value' => $this->getSetting('link'),
    ];

    

class DateTimeDatelistWidget extends DateTimeWidgetBase {

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'increment' => '15',
      'date_order' => 'YMD',
      'time_type' => '24',
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function formElement(FieldItemListInterface $items$delta, array $element, array &$form, FormStateInterface $form_state) {
    $element = parent::formElement($items$delta$element$form$form_state);

    // Wrap all of the select elements with a fieldset.     $element['#theme_wrappers'][] = 'fieldset';

    
parent::__construct($plugin_id$plugin_definition$field_definition$settings$third_party_settings$element_info);
    $this->imageFactory = $image_factory ?: \Drupal::service('image.factory');
  }

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'progress_indicator' => 'throbber',
      'preview_image_style' => 'thumbnail',
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::settingsForm($form$form_state);

    $element['preview_image_style'] = [
      '#title' => $this->t('Preview image style'),
      '#type' => 'select',
      

class DateRangeDatelistWidget extends DateRangeWidgetBase {

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'increment' => '15',
      'date_order' => 'YMD',
      'time_type' => '24',
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function formElement(FieldItemListInterface $items$delta, array $element, array &$form, FormStateInterface $form_state) {
    $element = parent::formElement($items$delta$element$form$form_state);

    $date_order = $this->getSetting('date_order');

    if ($this->getFieldSetting('datetime_type') == DateRangeItem::DATETIME_TYPE_DATETIME) {
      

class TestFieldDefaultFormatter extends FormatterBase {

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'test_formatter_setting' => 'dummy test string',
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element['test_formatter_setting'] = [
      '#title' => $this->t('Setting'),
      '#type' => 'textfield',
      '#size' => 20,
      '#default_value' => $this->getSetting('test_formatter_setting'),
      
return 'video';
  }

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'muted' => FALSE,
      'width' => 640,
      'height' => 480,
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    return parent::settingsForm($form$form_state) + [
      'muted' => [
        '#title' => $this->t('Muted'),
        '#type' => 'checkbox',
        '#default_value' => $this->getSetting('muted'),
      ],
$configuration['label'],
      $configuration['view_mode'],
      $configuration['third_party_settings'],
      $container->get('entity_type.manager')
    );
  }

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    $options = parent::defaultSettings();

    $options['link_to_entity'] = FALSE;
    return $options;
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $form = parent::settingsForm($form$form_state);
    $entity_type = $this->entityTypeManager->getDefinition($this->fieldDefinition->getTargetEntityTypeId());

    

class DateRangeDefaultFormatter extends DateTimeDefaultFormatter {

  use DateTimeRangeTrait;

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'separator' => '-',
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $form = parent::settingsForm($form$form_state);

    $form['separator'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Date separator'),
      

  }

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'future_format' => '@interval hence',
      'past_format' => '@interval ago',
      'granularity' => 2,
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $form = parent::settingsForm($form$form_state);

    $form['future_format'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Future format'),
      

class IntegerFormatter extends NumericFormatterBase {

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'thousand_separator' => '',
      'prefix_suffix' => TRUE,
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  protected function numberFormat($number) {
    return number_format($number, 0, '', $this->getSetting('thousand_separator'));
  }

}

class TestFieldEmptySettingFormatter extends FormatterBase {

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'field_empty_setting' => '',
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element['field_empty_setting'] = [
      '#title' => $this->t('Setting'),
      '#type' => 'textfield',
      '#size' => 20,
      '#default_value' => $this->getSetting('field_empty_setting'),
      
class TextareaWithSummaryWidget extends TextareaWidget {

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'rows' => '9',
      'summary_rows' => '3',
      'placeholder' => '',
      'show_summary' => FALSE,
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::settingsForm($form$form_state);
    $element['summary_rows'] = [
      '#type' => 'number',
      '#title' => $this->t('Summary rows'),
      '#default_value' => $this->getSetting('summary_rows'),
      

class TelephoneDefaultWidget extends WidgetBase {

  /** * {@inheritdoc} */
  public static function defaultSettings() {
    return [
      'placeholder' => '',
    ] + parent::defaultSettings();
  }

  /** * {@inheritdoc} */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element['placeholder'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Placeholder'),
      '#default_value' => $this->getSetting('placeholder'),
      '#description' => $this->t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
    ];
Home | Imprint | This part of the site doesn't use cookies.