You are here

function simple_node_importer_get_allowed_content_type_list in Simple Node Importer 8

Set dynamic allowed values for the alignment field.

Parameters

\Drupal\field\Entity\FieldStorageConfig $definition: The field definition.

\Drupal\Core\Entity\ContentEntityInterface|null $entity: The entity being created if applicable.

bool $cacheable: Boolean indicating if the results are cacheable.

Return value

array An array of possible key and value options.

See also

options_allowed_values()

1 string reference to 'simple_node_importer_get_allowed_content_type_list'
field.storage.node.field_select_content_type.yml in config/install/field.storage.node.field_select_content_type.yml
config/install/field.storage.node.field_select_content_type.yml

File

./simple_node_importer.module, line 536
Simple node importer module file.

Code

function simple_node_importer_get_allowed_content_type_list(FieldStorageConfig $definition, ContentEntityInterface $entity = NULL, $cacheable) {

  // Declare a variable for selected content type.
  $content_type_selected = [];

  // Add a custom alignment option for Article nodes.
  if ($entity
    ->bundle() == 'simple_node') {

    // Get the list of all allowed content types.
    $content_type_select = \Drupal::config('simple_node_importer.settings')
      ->get('content_type_select');
    $content_type_selected['_none'] = t("- Select a value -");
    if (!empty($content_type_select)) {
      foreach ($content_type_select as $key => $value) {
        if ($value) {
          $content_type_selected[$key] = str_replace("_", " ", $value);
        }
      }
    }
  }
  return $content_type_selected;
}