You are here

public function HideIfBoolCheck::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/HideIfBoolCheck.php, line 54

Class

HideIfBoolCheck
The plugin for check empty fields.

Namespace

Drupal\fico\Plugin\Field\FieldFormatter\Condition

Code

public function access(&$build, $field, $settings) {
  if (!($entity = $this
    ->getEntity($build))) {
    $build[$field]['#access'] = FALSE;
    return;
  }
  $items = $entity
    ->get($settings['settings']['target_field']);
  foreach ($items as $key => $item) {
    $value = $item
      ->getValue();
    if (empty($settings['settings']['negate']) && !empty($value['value']) || !empty($settings['settings']['negate']) && empty($value['value'])) {
      $build[$field]['#access'] = FALSE;
    }
  }
}