getFieldSettings example



    return $elements;
  }

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

    $field_settings = $this->getFieldSettings();

    // Add image validation.     $element['#upload_validators']['file_validate_is_image'] = [];

    // Add upload resolution validation.     if ($field_settings['max_resolution'] || $field_settings['min_resolution']) {
      $element['#upload_validators']['file_validate_image_resolution'] = [$field_settings['max_resolution']$field_settings['min_resolution']];
    }

    $extensions = $field_settings['file_extensions'];
    $supported_extensions = $this->imageFactory->getSupportedExtensions();

    
$summary[] = $this->t('No placeholder');
    }

    return $summary;
  }

  /** * {@inheritdoc} */
  public function formElement(FieldItemListInterface $items$delta, array $element, array &$form, FormStateInterface $form_state) {
    $value = $items[$delta]->value ?? NULL;
    $field_settings = $this->getFieldSettings();

    $element += [
      '#type' => 'number',
      '#default_value' => $value,
      '#placeholder' => $this->getSetting('placeholder'),
    ];

    // Set the step for floating point and decimal numbers.     switch ($this->fieldDefinition->getType()) {
      case 'decimal':
        $element['#step'] = pow(0.1, $field_settings['scale']);
        
'height' => NULL,
    ];
    $no_width_min_resolution = [
      'width' => NULL,
      'height' => 50,
    ];
    $no_width_max_resolution = [
      'width' => NULL,
      'height' => 100,
    ];
    $field_settings = [
      0 => $this->getFieldSettings($min_resolution$max_resolution),
      1 => $this->getFieldSettings($no_height_min_resolution$no_height_max_resolution),
      2 => $this->getFieldSettings($no_width_min_resolution$no_width_max_resolution),
    ];
    $this->createImageField($field_names[0], 'article', []$field_settings[0]);
    $this->createImageField($field_names[1], 'article', []$field_settings[1]);
    $this->createImageField($field_names[2], 'article', []$field_settings[2]);

    // We want a test image that is too small, and a test image that is too     // big, so cycle through test image files until we have what we need.     $image_that_is_too_big = FALSE;
    $image_that_is_too_small = FALSE;
    
$elements['#theme'] = 'file_widget_multiple';
      $elements['#theme_wrappers'] = ['details'];
      $elements['#process'] = [[static::class, 'processMultiple']];
      $elements['#title'] = $title;

      $elements['#description'] = $description;
      $elements['#field_name'] = $field_name;
      $elements['#language'] = $items->getLangcode();
      // The field settings include defaults for the field type. However, this       // widget is a base class for other widgets (e.g., ImageWidget) that may       // act on field types without these expected settings.       $field_settings = $this->getFieldSettings() + ['display_field' => NULL];
      $elements['#display_field'] = (bool) $field_settings['display_field'];

      // Add some properties that will eventually be added to the file upload       // field. These are added here so that they may be referenced easily       // through a hook_form_alter().       $elements['#file_upload_title'] = $this->t('Add a new file');
      $elements['#file_upload_description'] = [
        '#theme' => 'file_upload_help',
        '#description' => '',
        '#upload_validators' => $elements[0]['#upload_validators'],
        '#cardinality' => $cardinality,
      ];
$summary[] = $this->t('Display with prefix and suffix.');
    }

    return $summary;
  }

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

    foreach ($items as $delta => $item) {
      $output = $this->numberFormat($item->value);

      // Account for prefix and suffix.       if ($this->getSetting('prefix_suffix')) {
        $prefixes = isset($settings['prefix']) ? array_map(['Drupal\Core\Field\FieldFilteredMarkup', 'create']explode('|', $settings['prefix'])) : [''];
        $suffixes = isset($settings['suffix']) ? array_map(['Drupal\Core\Field\FieldFilteredMarkup', 'create']explode('|', $settings['suffix'])) : [''];
        $prefix = (count($prefixes) > 1) ? $this->formatPlural($item->value, $prefixes[0]$prefixes[1]) : $prefixes[0];
        $suffix = (count($suffixes) > 1) ? $this->formatPlural($item->value, $suffixes[0]$suffixes[1]) : $suffixes[0];
        $output = $prefix . $output . $suffix;
      }
$field_name = $this->fieldDefinition->getName();
    $entity = $items->getEntity();

    $status = $items->status;

    if ($status != CommentItemInterface::HIDDEN && empty($entity->in_preview) &&
      // Comments are added to the search results and search index by       // comment_node_update_index() instead of by this formatter, so don't       // return anything if the view mode is search_index or search_result.       !in_array($this->viewMode, ['search_result', 'search_index'])) {
      $comment_settings = $this->getFieldSettings();

      // Only attempt to render comments if the entity has visible comments.       // Unpublished comments are not included in       // $entity->get($field_name)->comment_count, but unpublished comments       // should display if the user is an administrator.       $elements['#cache']['contexts'][] = 'user.permissions';
      if ($this->currentUser->hasPermission('access comments') || $this->currentUser->hasPermission('administer comments')) {
        $output['comments'] = [];

        if ($entity->get($field_name)->comment_count || $this->currentUser->hasPermission('administer comments')) {
          $mode = $comment_settings['default_mode'];
          
Home | Imprint | This part of the site doesn't use cookies.