You are here

public function NodeField::summary in Entity Field Condition 8

Provides a human readable summary of the condition's configuration.

Overrides ConditionInterface::summary

File

src/Plugin/Condition/NodeField.php, line 334

Class

NodeField
Provides a 'Node Field' condition.

Namespace

Drupal\entity_field_condition\Plugin\Condition

Code

public function summary() {

  // Entity Type.
  $entity_type_id = $this->configuration['entity_type_id'];
  $entity_type_definition = $this->entityTypeManager
    ->getDefinition($entity_type_id);

  // Entity Bundle.
  $entity_bundle = $this->configuration['entity_bundle'];

  // Field.
  $field = $this->configuration['field'];
  $field_label = '';

  // Get Field label.
  foreach ($this->entityFieldManager
    ->getFieldDefinitions($entity_type_id, $entity_bundle) as $field_definition) {
    if ($field_definition
      ->getName() === $field) {
      $field_label = (string) $field_definition
        ->getLabel();
    }
  }
  return $this
    ->t('@entity_type "@entity_bundle" field "@field" is "@value"', [
    '@entity_type' => $entity_type_definition
      ->getLabel(),
    '@entity_bundle' => $entity_bundle,
    '@field' => $field_label,
    '@value' => $this->configuration['value_source'] === 'null' ? 'is NULL' : $this->configuration['value'],
  ]);
}