You are here

protected function NodeField::getNodeFields in Entity Field Condition 8

Return the fields for a content type.

Parameters

string $node_type: The node type machine name.

Return value

array Returns the available fields for the content type.

2 calls to NodeField::getNodeFields()
NodeField::buildConfigurationForm in src/Plugin/Condition/NodeField.php
Form constructor.
NodeField::fieldsCallback in src/Plugin/Condition/NodeField.php
Handles switching the available fields.

File

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

Class

NodeField
Provides a 'Node Field' condition.

Namespace

Drupal\entity_field_condition\Plugin\Condition

Code

protected function getNodeFields($node_type) {
  $labels = $this
    ->getEmptyOption();
  if (empty($node_type)) {
    return $labels;
  }

  // Getting the fields for the content type.
  $node_fields = $this->entityFieldManager
    ->getFieldDefinitions('node', $node_type);

  // Getting the field definitions.
  $field_types = $this->fieldTypePluginManager
    ->getDefinitions();
  foreach ($node_fields as $field) {

    // Get the field type label.
    $field_type_label = $field_types[$field
      ->getType()]['label']
      ->getUntranslatedString();
    $labels[$field_type_label][$field
      ->getName()] = $field
      ->getLabel();
  }
  return $labels;
}