You are here

private function PageContext::getAvailableFieldVocabularyNames in Acquia Lift Connector 8.4

Same name and namespace in other branches
  1. 8 src/Service/Context/PageContext.php \Drupal\acquia_lift\Service\Context\PageContext::getAvailableFieldVocabularyNames()
  2. 8.3 src/Service/Context/PageContext.php \Drupal\acquia_lift\Service\Context\PageContext::getAvailableFieldVocabularyNames()

Get available Fields and their vocabulary names within the node.

Parameters

\Drupal\node\NodeInterface $node: Node.

Return value

array Node's available Fields' Vocabularies names.

1 call to PageContext::getAvailableFieldVocabularyNames()
PageContext::setFields in src/Service/Context/PageContext.php
Set fields.

File

src/Service/Context/PageContext.php, line 294

Class

PageContext

Namespace

Drupal\acquia_lift\Service\Context

Code

private function getAvailableFieldVocabularyNames(NodeInterface $node) {
  $available_field_vocabulary_names = [];
  $available_field_vocabulary_fields = [];

  // Regular field mapping
  foreach ($this->fieldMappings as $page_context_name => $field_name) {
    if (!isset($node->{$field_name})) {
      continue;
    }

    // Add this field to the list of fields to parse with their corresponding
    // page context name;
    if (!isset($available_field_vocabulary_fields[$field_name])) {
      $available_field_vocabulary_fields[$field_name] = [];
    }
    $available_field_vocabulary_fields[$field_name][] = $page_context_name;
  }

  // The following 3 mappings have all the same structure with different array
  // id's so we can merge them without conflict.
  $udf_mappings = array_merge($this->udfPersonMappings, $this->udfTouchMappings, $this->udfEventMappings);
  foreach ($udf_mappings as $page_context_name => $properties) {
    if (!isset($node->{$properties['value']})) {
      continue;
    }

    // Add this field to the list of fields to parse with their corresponding
    // page context name;
    if (!isset($available_field_vocabulary_fields[$properties['value']])) {
      $available_field_vocabulary_fields[$properties['value']] = [];
    }
    $available_field_vocabulary_fields[$properties['value']][] = $page_context_name;
  }
  foreach ($available_field_vocabulary_fields as $field_name => $page_contexts) {
    $field_handler_settings = $node->{$field_name}
      ->getSetting('handler_settings');
    $vocabulary_names = array_key_exists('target_bundles', $field_handler_settings) ? $field_handler_settings['target_bundles'] : [];
    foreach ($page_contexts as $page_context_name) {
      $available_field_vocabulary_names[$page_context_name] = $vocabulary_names;
    }
  }
  return $available_field_vocabulary_names;
}