You are here

protected function SchemaNameBase::processItem in Schema.org Metatag 7

Process an individual item.

This is a copy of the original processing done by Metatag module, but applied to every item on the array of values.

1 call to SchemaNameBase::processItem()
SchemaNameBase::getElement in src/SchemaNameBase.php
Get the HTML tag for this meta tag.

File

src/SchemaNameBase.php, line 189

Class

SchemaNameBase
All Schema.org tags should extend this class.

Code

protected function processItem(&$value, $key = 0) {
  $explode = $key === 0 ? $this
    ->multiple() : !in_array($key, static::neverExplode());

  // $this->getValue() will process all subelements of our array
  // but not all of them need that processing.
  // Swap in the individual values/info as though they were the only
  // values, do the processing, then return to the original values.
  $backup_data = $this->data;
  $backup_info = $this->info;
  $this->data['value'] = $value;
  if (!empty($this->info['url'])) {
    $this->info['url'] = $this->info['url'] && in_array($key, [
      'url',
      'sameAs',
    ]);
  }
  if (!empty($this->info['image'])) {
    $this->info['image'] = $this->info['image'] && in_array($key, [
      'url',
    ]);
  }
  $value = $this
    ->getValue($this->options);
  if ($explode) {
    $value = $this
      ->schemaMetatagManager()
      ->explode($value);

    // Clean out any empty values that might have been added by explode().
    if (is_array($value)) {
      $value = array_filter($value);
    }
  }

  // Swap back in the original values.
  $this->data = $backup_data;
  $this->info = $backup_info;
}