You are here

public function ContentProcessor::processMetatagPane in GatherContent 8.4

Processing function for metatag panes.

Parameters

\Drupal\node\NodeInterface $entity: Object of node.

string $local_field_name: ID of local Drupal field.

object $field: Object of GatherContent field.

string $content_type: Name of Content type, we are mapping to.

bool $is_translatable: Indicator if node is translatable.

string $language: Language of translation if applicable.

Throws

\Exception If content save fails, exceptions is thrown.

1 call to ContentProcessor::processMetatagPane()
ContentProcessor::createNode in src/Import/ContentProcess/ContentProcessor.php
Create a Drupal node filled with the properties of the GC item.

File

src/Import/ContentProcess/ContentProcessor.php, line 378

Class

ContentProcessor
The ContentProcessor sets the necessary fields of the entity.

Namespace

Drupal\gathercontent\Import\ContentProcess

Code

public function processMetatagPane(NodeInterface &$entity, $local_field_name, $field, $content_type, $is_translatable, $language) {
  if (\Drupal::moduleHandler()
    ->moduleExists('metatag') && $this->metatag
    ->checkMetatag($content_type)) {
    $metatag_fields = $this->metatag
      ->getMetatagFields($content_type);
    foreach ($metatag_fields as $metatag_field) {
      if ($is_translatable) {
        $current_value = unserialize($entity
          ->getTranslation($language)->{$metatag_field}->value);
        $current_value[$local_field_name] = $field->value;
        $entity
          ->getTranslation($language)->{$metatag_field}->value = serialize($current_value);
      }
      else {
        $current_value = unserialize($entity->{$metatag_field}->value);
        $current_value[$local_field_name] = $field->value;
        $entity->{$metatag_field}->value = serialize($current_value);
      }
    }
  }
  else {
    throw new \Exception("Metatag module not enabled or entity doesn't support\n    metatags while trying to map values with metatag content.");
  }
}