You are here

class SchemaItemListBase in Schema.org Metatag 7

Provides a plugin for the 'schema_item_list' meta tag.

Hierarchy

Expanded class hierarchy of SchemaItemListBase

File

src/SchemaItemListBase.php, line 6

View source
class SchemaItemListBase extends SchemaNameBase {

  /**
   * {@inheritdoc}
   */
  public function getElement(array $options = array()) {
    $element = parent::getElement($options);
    if (!empty($element)) {
      $view = $options['token data']['view'];
      $id = $view->base_field;
      $entity_type = $view->base_table;
      $key = 1;
      $value = [];
      foreach ($view->result as $item) {

        // If this is a display that does not provide an entity in the result,
        // there is really nothing more to do.
        if (empty($item->{$id})) {
          return '';
        }

        // Get the absolute path to this entity.
        $entity = entity_load($entity_type, [
          $item->{$id},
        ]);
        $entity = array_shift($entity);
        $uri = entity_uri($entity_type, $entity);
        $url = drupal_get_path_alias($uri['path']);
        $absolute = url($url, array(
          'absolute' => TRUE,
        ));
        $value[] = [
          '@type' => 'ListItem',
          'position' => $key,
          'name' => $entity->title,
          'url' => $absolute,
        ];
        $key++;
      }
      foreach ($element['#attached']['drupal_add_html_head'] as $key => $item) {
        if ($item[1] == 'schema_metatag_schema_item_list.itemListElement') {
          $element['#attached']['drupal_add_html_head'][$key][0]['#attributes']['content'] = $value;
        }
      }
    }
    return $element;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalDefaultMetaTag::$data protected property The values submitted for this tag.
DrupalDefaultMetaTag::$info protected property All of the basic information about this tag.
DrupalDefaultMetaTag::$weight protected property This item's weight; used for sorting the output.
DrupalDefaultMetaTag::convertUrlToAbsolute protected function Make sure a given URL is absolute.
DrupalDefaultMetaTag::getWeight public function Calculate the weight of this meta tag. Overrides DrupalMetaTagInterface::getWeight
DrupalDefaultMetaTag::maxlength protected function Identify the maximum length of which strings will be allowed.
DrupalDefaultMetaTag::textSummary public static function Copied from text.module with the following changes:. Overrides DrupalMetaTagInterface::textSummary
DrupalDefaultMetaTag::tidyValue protected function Remove unwanted formatting from a meta tag.
DrupalDefaultMetaTag::truncate protected function Shorten a string to a certain length using ::textSummary().
DrupalTextMetaTag::getValue public function Get the string value of this meta tag. Overrides DrupalDefaultMetaTag::getValue 1
SchemaItemListBase::getElement public function Get the HTML tag for this meta tag. Overrides SchemaNameBase::getElement
SchemaNameBase::$schemaMetatagManager protected property The schemaMetatagManager service.
SchemaNameBase::description public function
SchemaNameBase::getForm public function Build the form for this meta tag. Overrides DrupalTextMetaTag::getForm 32
SchemaNameBase::getPluginId public function
SchemaNameBase::label public function
SchemaNameBase::multiple public function
SchemaNameBase::neverExplode public static function Nested elements that cannot be exploded.
SchemaNameBase::outputValue public static function Transform input value to its display output. Overrides SchemaMetatagTestTagInterface::outputValue 2
SchemaNameBase::pivotItem public static function
SchemaNameBase::processedTestValue public static function Provide a test output value for the input value. Overrides SchemaMetatagTestTagInterface::processedTestValue 17
SchemaNameBase::processItem protected function Process an individual item.
SchemaNameBase::processTestExplodeValue public static function Explode a test value. Overrides SchemaMetatagTestTagInterface::processTestExplodeValue
SchemaNameBase::randomUrl public static function Random absolute url for testing. Overrides SchemaMetatagTestTagInterface::randomUrl
SchemaNameBase::schemaMetatagManager protected function Return the SchemaMetatagManager.
SchemaNameBase::t public function
SchemaNameBase::testDefaultValue public static function Provide a random test value. Overrides SchemaMetatagTestTagInterface::testDefaultValue
SchemaNameBase::testValue public static function Provide a test input value for the property that will validate. Overrides SchemaMetatagTestTagInterface::testValue 33
SchemaNameBase::value public function
SchemaNameBase::visibilitySelector protected function The #states visibility selector for this element.
SchemaNameBase::__construct function Constructor. Overrides DrupalDefaultMetaTag::__construct 1