settingsSummary example

'#options' => $options,
      '#default_value' => $this->getSetting('format_type'),
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();

    $date = new DrupalDateTime();
    $summary[] = $this->t('Format: @display', ['@display' => $this->formatDate($date)]);

    return $summary;
  }

}
'#description' => $this->t('The preview image will be shown while editing the content.'),
      '#weight' => 15,
    ];

    return $element;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();

    $image_styles = image_style_options(FALSE);
    // Unset possible 'No defined styles' option.     unset($image_styles['']);
    // Styles could be lost because of enabled/disabled modules that defines     // their styles in code.     $image_style_setting = $this->getSetting('preview_image_style');
    if (isset($image_styles[$image_style_setting])) {
      $preview_image_style = $this->t('Preview image style: @style', ['@style' => $image_styles[$image_style_setting]]);
    }
    else {
      
'value' => static::CUSTOM_DATE_FORMAT,
      ]),
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();

    $time_diff = $this->getSetting('time_diff');
    $date_format = $this->getSetting('date_format');
    $date_format = $date_format === static::CUSTOM_DATE_FORMAT ? $this->getSetting('custom_date_format') : $date_format;

    if ($time_diff['enabled']) {
      $summary[] = $this->t('Displayed as a time difference');

      $options = ['granularity' => $time_diff['granularity']];

      $timestamp = strtotime('1 year 1 month 1 week 1 day 1 hour 1 minute');
      
'#field_suffix' => $this->t('pixels'),
        '#min' => 0,
        '#required' => TRUE,
      ],
    ];
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();
    $summary[] = $this->t('Muted: %muted', ['%muted' => $this->getSetting('muted') ? $this->t('yes') : $this->t('no')]);
    $summary[] = $this->t('Size: %width x %height pixels', [
      '%width' => $this->getSetting('width'),
      '%height' => $this->getSetting('height'),
    ]);
    return $summary;
  }

  /** * {@inheritdoc} */
  

  public function testSettingsSummary(array $settings, array $expected_summary): void {
    /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
    $display = \Drupal::service('entity_display.repository')->getViewDisplay($this->testEntityTypeId, $this->testEntityBundleId);
    $display->setComponent($this->mediaFieldName, [
      'type' => 'media_thumbnail',
      'settings' => $settings,
    ]);
    $formatter = $display->getRenderer($this->mediaFieldName);
    $actual_summary = array_map('strval', $formatter->settingsSummary());
    $this->assertSame($expected_summary$actual_summary);
  }

  /** * Data provider for testSettingsSummary(). * * @return array[] */
  public function providerTestSettingsSummary(): array {
    return [
      'link to content' => [
        [
'#options' => TimeZoneFormHelper::getOptionsListByRegion(TRUE),
      '#default_value' => $this->getSetting('timezone_override'),
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();

    if ($override = $this->getSetting('timezone_override')) {
      $summary[] = $this->t('Time zone: @timezone', ['@timezone' => $override]);
    }

    return $summary;
  }

  /** * {@inheritdoc} */
  

    $form['loading']['attribute']['lazy']['#description'] = $this->t('Delays loading the resource until that section of the page is visible in the browser. When in doubt, lazy loading is recommended.');
    $form['loading']['attribute']['eager']['#description'] = $this->t('Force browsers to download a resource as soon as possible. This is the browser default for legacy reasons. Only use this option when the resource is always expected to render.');

    return $form;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();
    if ($this->getSetting('max_width') && $this->getSetting('max_height')) {
      $summary[] = $this->t('Maximum size: %max_width x %max_height pixels', [
        '%max_width' => $this->getSetting('max_width'),
        '%max_height' => $this->getSetting('max_height'),
      ]);
    }
    elseif ($this->getSetting('max_width')) {
      $summary[] = $this->t('Maximum width: %max_width pixels', [
        '%max_width' => $this->getSetting('max_width'),
      ]);
    }
    
'#type' => 'checkbox',
      '#title' => $this->t('Always show the summary field'),
      '#default_value' => $this->getSetting('show_summary'),
    ];
    return $element;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();

    $summary[] = $this->t('Number of summary rows: @rows', ['@rows' => $this->getSetting('summary_rows')]);
    if ($this->getSetting('show_summary')) {
      $summary[] = $this->t('Summary field will always be visible');
    }

    return $summary;
  }

  /** * {@inheritdoc} */
'media' => $this->t('Media item'),
    ];
    $element['image_link']['#options'] = $link_types;

    return $element;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();

    // The parent class adds summary text if the image_link setting is     // 'content'. Here we only have to add summary text if the setting     // is 'media'.     if ($this->getSetting('image_link') === 'media') {
      $summary[] = $this->t('Linked to media item');
    }

    return $summary;
  }

  
'#description' => $this->t('The string to separate the start and end dates'),
      '#default_value' => $this->getSetting('separator'),
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();

    if ($separator = $this->getSetting('separator')) {
      $summary[] = $this->t('Separator: %separator', ['%separator' => $separator]);
    }

    return $summary;
  }

}
$field_row['#attributes']['class'][] = 'field-plugin-settings-editing';
        }
      }
    }
    else {
      $field_row['settings_summary'] = [];
      $field_row['settings_edit'] = [];

      if ($plugin) {
        // Display a summary of the current plugin settings, and (if the         // summary is not empty) a button to edit them.         $summary = $plugin->settingsSummary();

        // Allow other modules to alter the summary.         $this->alterSettingsSummary($summary$plugin$field_definition);

        if (!empty($summary)) {
          $field_row['settings_summary'] = [
            '#type' => 'inline_template',
            '#template' => '<div class="field-plugin-summary">{{ summary|safe_join("<br />") }}</div>',
            '#context' => ['summary' => $summary],
            '#cell_attributes' => ['class' => ['field-plugin-summary-cell']],
          ];
        }
'#min' => 1,
      '#max' => 6,
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();

    $future_date = new DrupalDateTime('1 year 1 month 1 week 1 day 1 hour 1 minute');
    $past_date = new DrupalDateTime('-1 year -1 month -1 week -1 day -1 hour -1 minute');
    $granularity = $this->getSetting('granularity');
    $options = [
      'granularity' => $granularity,
      'return_as_object' => FALSE,
    ];

    $future_date_interval = new FormattableMarkup($this->getSetting('future_format')['@interval' => $this->dateFormatter->formatTimeDiffUntil($future_date->getTimestamp()$options)]);
    $past_date_interval = new FormattableMarkup($this->getSetting('past_format')['@interval' => $this->dateFormatter->formatTimeDiffSince($past_date->getTimestamp()$options)]);

    
'#description' => $this->t('The string to separate the start and end dates'),
      '#default_value' => $this->getSetting('separator'),
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();

    if ($separator = $this->getSetting('separator')) {
      $summary[] = $this->t('Separator: %separator', ['%separator' => $separator]);
    }

    return $summary;
  }

}
'#description' => $this->t('The string to separate the start and end dates'),
      '#default_value' => $this->getSetting('separator'),
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function settingsSummary() {
    $summary = parent::settingsSummary();

    if ($separator = $this->getSetting('separator')) {
      $summary[] = $this->t('Separator: %separator', ['%separator' => $separator]);
    }

    return $summary;
  }

}
    unset($image_styles['']);
    // Styles could be lost because of enabled/disabled modules that defines     // their styles in code.     $image_style_setting = $this->getSetting('image_style');
    if (isset($image_styles[$image_style_setting])) {
      $summary[] = $this->t('Image style: @style', ['@style' => $image_styles[$image_style_setting]]);
    }
    else {
      $summary[] = $this->t('Original image');
    }

    return array_merge($summary, parent::settingsSummary());
  }

  /** * {@inheritdoc} */
  public function viewElements(FieldItemListInterface $items$langcode) {
    $elements = [];

    /** @var \Drupal\Core\Field\EntityReferenceFieldItemListInterface $items */
    if (empty($images = $this->getEntitiesToView($items$langcode))) {
      // Early opt-out if the field is empty.
Home | Imprint | This part of the site doesn't use cookies.