You are here

function _workflow_info_fields in Workflow 8

Same name and namespace in other branches
  1. 7.2 workflow.module \_workflow_info_fields()

Gets the workflow field names, if not known already.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: Object to work with. May be empty, e.g., on menu build.

string $entity_type: Entity type of object. Optional, but required if $entity provided.

string $entity_bundle: Bundle of entity. Optional.

string $field_name: Field name. Optional.

Return value

Drupal\field\Entity\FieldStorageConfig[] An array of FieldStorageConfig objects.

12 calls to _workflow_info_fields()
Workflow::isDeletable in src/Entity/Workflow.php
Returns if the Workflow may be deleted.
WorkflowFieldConstraintValidator::isValidFieldname in src/Plugin/Validation/Constraint/WorkflowFieldConstraintValidator.php
WorkflowHistoryAccess::access in src/Access/WorkflowHistoryAccess.php
Check if the user has permissions to view this workflow.
WorkflowItem::storageSettingsForm in src/Plugin/Field/FieldType/WorkflowItem.php
Implements hook_field_settings_form() -> ConfigFieldItemInterface::settingsForm().
WorkflowState::count in src/Entity/WorkflowState.php
Returns the number of entities with this state.

... See full list

File

./workflow.module, line 598
Support workflows made up of arbitrary states.

Code

function _workflow_info_fields($entity = NULL, $entity_type = '', $entity_bundle = '', $field_name = '') {
  $field_info = [];

  // Figure out the $entity's bundle and id.
  if ($entity) {
    $entity_type = $entity
      ->getEntityTypeId();
    $entity_bundle = $entity
      ->bundle();
  }
  else {

    // Entity type and bundle should be specified.
  }
  $field_list = \Drupal::service('entity_field.manager')
    ->getFieldMapByFieldType('workflow');
  foreach ($field_list as $e_type => $data) {
    if (!$entity_type || $entity_type == $e_type) {
      foreach ($data as $f_name => $value) {
        if (!$entity_bundle || isset($value['bundles'][$entity_bundle])) {
          if (!$field_name || $field_name == $f_name) {

            // Do not use the field_name as ID, but the
            // unique <entity_type>.<field_name> since you cannot share the
            // same field on multiple entity_types (unlike D7).
            $field_config = FieldStorageConfig::loadByName($e_type, $f_name);
            if ($field_config) {
              $field_info[$field_config
                ->id()] = $field_config;
            }
            else {

              // The field is a base/extra field.
              // not a configurable Field via Field UI.
              // Re-fetch the field definitions, with extra data.
              $field_definitions = \Drupal::service('entity_field.manager')
                ->getFieldDefinitions($e_type, $entity_bundle);

              // @todo Loop over bundles?

              /** @var \Drupal\Core\Field\BaseFieldDefinition $field_config */
              $field_config = $field_definitions[$f_name];
              if ($field_config) {
                $field_info[$field_config
                  ->getUniqueStorageIdentifier()] = $field_config;
              }
              else {

                // @todo Loop over bundles?
              }
            }
          }
        }
      }
    }
  }
  return $field_info;
}