You are here

class NodeTitle in Exclude Node Title 8

Extended NodeTitle Display Suite plugin.

Hierarchy

Expanded class hierarchy of NodeTitle

File

src/Plugin/DsField/Node/NodeTitle.php, line 14

Namespace

Drupal\exclude_node_title\Plugin\DsField\Node
View source
class NodeTitle extends DsNodeTitle {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function settingsForm($form, FormStateInterface $form_state) {
    $settings = Title::settingsForm($form, $form_state);
    $config = $this
      ->getConfiguration();
    $settings['exclude_node_title'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Use Exclude Node Title'),
      '#options' => [
        'No',
        'Yes',
      ],
      '#description' => $this
        ->t('Use the settings for the Exclude Node Title module for the title. Set to "off" to always show title.'),
      '#default_value' => $config['exclude_node_title'],
    ];
    return $settings;
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary($settings) {
    $summary = Title::settingsSummary($settings);
    $config = $this
      ->getConfiguration();
    if (!empty($config['exclude_node_title'])) {
      $summary[] = $this
        ->t('Use Exclude Node Title: yes');
    }
    else {
      $summary[] = $this
        ->t('Use Exclude Node Title: no');
    }
    return $summary;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    $configuration = Title::defaultConfiguration();
    $configuration['exclude_node_title'] = 1;
    return $configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function build() {
    $config = $this
      ->getConfiguration();
    if ($config['exclude_node_title']) {
      $exclude_manager = \Drupal::service('exclude_node_title.manager');
      if ($exclude_manager
        ->isTitleExcluded($this
        ->entity(), $this
        ->viewMode())) {
        return [
          '#markup' => '',
        ];
      }
    }
    return Field::build();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NodeTitle::build public function
NodeTitle::defaultConfiguration public function
NodeTitle::settingsForm public function
NodeTitle::settingsSummary public function
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.