You are here

public function HideLinkWhenTitleIsEmpty::access in Field Formatter Condition 8

Access control function.

Parameters

array $build: The current build array.

string $field: The current field name.

array $settings: The current settings array.

Overrides FieldFormatterConditionBase::access

File

src/Plugin/Field/FieldFormatter/Condition/HideLinkWhenTitleIsEmpty.php, line 29

Class

HideLinkWhenTitleIsEmpty
The plugin for check empty fields.

Namespace

Drupal\fico\Plugin\Field\FieldFormatter\Condition

Code

public function access(&$build, $field, $settings) {
  if (!empty($build[$field]['#items'])) {
    foreach ($build[$field]['#items'] as $item) {
      $info = $item
        ->getValue($field);
      if (!$info['title'] || $info['title'] === $info['uri']) {
        $build[$field]['#access'] = FALSE;
      }
    }
  }
  if (empty($build[$field]['#items'])) {
    $build[$field]['#access'] = FALSE;
  }
}