You are here

abstract class ExtraFieldPlusDisplayBase in Extra Field Settings Provider 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/ExtraFieldPlusDisplayBase.php \Drupal\extra_field_plus\Plugin\ExtraFieldPlusDisplayBase

Base class for Extra field Plus Display plugins.

Hierarchy

Expanded class hierarchy of ExtraFieldPlusDisplayBase

1 file declares its use of ExtraFieldPlusDisplayBase
ExampleNodeLabel.php in modules/extra_field_plus_example/src/Plugin/ExtraField/Display/ExampleNodeLabel.php

File

src/Plugin/ExtraFieldPlusDisplayBase.php, line 11

Namespace

Drupal\extra_field_plus\Plugin
View source
abstract class ExtraFieldPlusDisplayBase extends ExtraFieldDisplayBase implements ExtraFieldPlusDisplayInterface {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function getSettings() {
    $field_id = 'extra_field_' . $this
      ->getPluginId();
    $display = $this
      ->getEntityViewDisplay();
    $component = $display
      ->getComponent($field_id);
    $default_settings = (array) $this
      ->getDefaultFormValues();
    if (!empty($component['settings'])) {
      $settings = array_merge($default_settings, array_intersect_key($component['settings'], $default_settings));
    }
    else {
      $settings = $default_settings;
    }
    return $settings;
  }

  /**
   * {@inheritdoc}
   */
  public function getSetting($name) {
    $settings = $this
      ->getSettings();
    return isset($settings[$name]) ? $settings[$name] : NULL;
  }

  /**
   * Provides field settings form.
   *
   * @return array
   *   The field settings form.
   */
  protected function settingsForm() {
    $elements = [];
    return $elements;
  }

  /**
   * {@inheritdoc}
   */
  public function getSettingsForm() {
    $default_values = (array) $this
      ->getDefaultFormValues();
    $elements = (array) $this
      ->settingsForm();
    if (!empty($elements)) {
      foreach ($elements as $name => &$element) {
        $element['#default_value'] = isset($default_values[$name]) ? $default_values[$name] : '';
      }
    }
    return $elements;
  }

  /**
   * Provides field settings form default values.
   *
   * @return array
   *   The form values.
   */
  protected function defaultFormValues() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultFormValues() {
    return $this
      ->defaultFormValues();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExtraFieldPlusDisplayBase::defaultFormValues protected function Provides field settings form default values. 2
ExtraFieldPlusDisplayBase::getDefaultFormValues public function Returns field settings form default values. Overrides ExtraFieldPlusDisplayInterface::getDefaultFormValues
ExtraFieldPlusDisplayBase::getSetting public function Returns field setting. Overrides ExtraFieldPlusDisplayInterface::getSetting
ExtraFieldPlusDisplayBase::getSettings public function Returns field settings. Overrides ExtraFieldPlusDisplayInterface::getSettings
ExtraFieldPlusDisplayBase::getSettingsForm public function Returns field settings form. Overrides ExtraFieldPlusDisplayInterface::getSettingsForm
ExtraFieldPlusDisplayBase::settingsForm protected function Provides field settings form. 2
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.