You are here

public function SchemaNameBase::output in Schema.org Metatag 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/metatag/Tag/SchemaNameBase.php \Drupal\schema_metatag\Plugin\metatag\Tag\SchemaNameBase::output()

Generate the HTML tag output for a meta tag.

Return value

array|string A render array or an empty string.

Overrides MetaNameBase::output

File

src/Plugin/metatag/Tag/SchemaNameBase.php, line 128

Class

SchemaNameBase
All Schema.org tags should extend this class.

Namespace

Drupal\schema_metatag\Plugin\metatag\Tag

Code

public function output() {
  $value = $this
    ->schemaMetatagManager()
    ->unserialize($this
    ->value());

  // If this is a complex array of values, process the array.
  if (is_array($value)) {

    // Clean out empty values.
    $value = $this
      ->schemaMetatagManager()
      ->arrayTrim($value);
  }
  if (empty($value)) {
    return '';
  }
  elseif (is_array($value)) {

    // If the item is an array of values,
    // walk the array and process the values.
    array_walk_recursive($value, 'static::processItem');

    // Recursively pivot each branch of the array.
    $value = $this
      ->pivotItem($value);
  }
  else {
    $this
      ->processItem($value);
  }
  $output = [
    '#tag' => 'meta',
    '#attributes' => [
      'name' => $this->name,
      'content' => $this
        ->outputValue($value),
      'group' => $this->group,
      'schema_metatag' => TRUE,
    ],
  ];
  return $output;
}