You are here

class BreadcrumbList in Schema.org Metatag 8.2

Provides a plugin for the 'ItemListElement' Schema.org property type.

Plugin annotation


@SchemaPropertyType(
  id = "breadcrumb_list",
  label = @Translation("BreadcrumbList"),
  tree_parent = {
    "BreadcrumbList",
  },
  tree_depth = -1,
  property_type = "BreadcrumbList",
  sub_properties = {},
)

Hierarchy

Expanded class hierarchy of BreadcrumbList

1 string reference to 'BreadcrumbList'
BreadcrumbList::outputValue in src/Plugin/schema_metatag/PropertyType/BreadcrumbList.php
Transform input value to its display output.

File

src/Plugin/schema_metatag/PropertyType/BreadcrumbList.php, line 21

Namespace

Drupal\schema_metatag\Plugin\schema_metatag\PropertyType
View source
class BreadcrumbList extends ItemListElement {

  /**
   * {@inheritdoc}
   */
  public function form($input_values) {
    $value = $input_values['value'];
    $form = [
      '#type' => 'select',
      '#title' => $input_values['title'],
      '#description' => $input_values['description'],
      '#default_value' => !empty($value) ? $value : '',
      '#maxlength' => 255,
      '#empty_option' => $this
        ->t('No'),
      '#empty_value' => '',
      '#options' => [
        'Yes' => $this
          ->t('Yes'),
      ],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function testValue($type = '') {
    return 'Yes';
  }

  /**
   * {@inheritdoc}
   */
  public function outputValue($input_value) {
    $output_value = parent::outputValue($input_value);
    $items = [];
    if (!empty($output_value)) {
      $items = [
        "@type" => "BreadcrumbList",
        "itemListElement" => $output_value,
      ];
    }
    return $items;
  }

  /**
   * {@inheritdoc}
   */
  public function getItems($input_value) {
    $values = [];
    if (!empty($input_value)) {
      $entity_route = \Drupal::service('current_route_match')
        ->getCurrentRouteMatch();
      $breadcrumbs = \Drupal::service('breadcrumb')
        ->build($entity_route)
        ->getLinks();
      $key = 1;
      foreach ($breadcrumbs as $item) {

        // Modules that add the current page to the breadcrumb set it to an
        // empty path, so an empty path is the current path.
        $url = $item
          ->getUrl()
          ->setAbsolute()
          ->toString();
        if (empty($url)) {
          $url = Url::fromRoute('<current>')
            ->setAbsolute()
            ->toString();
        }
        $text = $item
          ->getText();
        $text = is_object($text) ? $text
          ->render() : $text;
        $values[$key] = [
          '@id' => $url,
          'name' => $text,
          'item' => $url,
        ];
        $key++;
      }
    }
    return $values;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BreadcrumbList::form public function Create a complete form element for this property type. Overrides ItemListElement::form
BreadcrumbList::getItems public function Overrides ItemListElement::getItems
BreadcrumbList::outputValue public function Transform input value to its display output. Overrides ItemListElement::outputValue
BreadcrumbList::testValue public function Provide a test input value for the property that will validate. Overrides ItemListElement::testValue
ItemListElement::getEntityFromRow protected static function Tries to retrieve an entity from a Views row.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
PropertyTypeBase::$propertyTypeManager protected property The propertyTypeManager service.
PropertyTypeBase::$schemaMetatagClient protected property The SchemaMetatagClient service.
PropertyTypeBase::$schemaMetatagManager protected property The schemaMetatagManager service.
PropertyTypeBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
PropertyTypeBase::formElement public function A property form element. Overrides PropertyTypeInterface::formElement 5
PropertyTypeBase::getChildPropertyType public function Get an instance of a child property type. Overrides PropertyTypeInterface::getChildPropertyType
PropertyTypeBase::getOptionList public function Create an option list for a given tree section. Overrides PropertyTypeInterface::getOptionList
PropertyTypeBase::getPropertyType public function The property type. Overrides PropertyTypeInterface::getPropertyType
PropertyTypeBase::getSubProperties public function The sub-properties. Overrides PropertyTypeInterface::getSubProperties
PropertyTypeBase::getTree public function Get some or all of the object tree as options for @type. Overrides PropertyTypeInterface::getTree
PropertyTypeBase::getTreeDepth public function The depth of the class tree to use for @type options. Overrides PropertyTypeInterface::getTreeDepth
PropertyTypeBase::getTreeParent public function The classes to use for the @type options of this property. Overrides PropertyTypeInterface::getTreeParent
PropertyTypeBase::getVisibility public function Construct the visibility selector for a set of values. Overrides PropertyTypeInterface::getVisibility
PropertyTypeBase::pivotForm public function Pivot form element. Overrides PropertyTypeInterface::pivotForm
PropertyTypeBase::processedTestValue public function Provide a test output value for the input value. Overrides SchemaMetatagTestTagInterface::processedTestValue
PropertyTypeBase::processTestExplodeValue public function Explode a test value. Overrides SchemaMetatagTestTagInterface::processTestExplodeValue
PropertyTypeBase::propertyInfo public function Get all the properties of a property type. Overrides PropertyTypeInterface::propertyInfo
PropertyTypeBase::schemaMetatagClient public function The Schema Metatag Client service. Overrides PropertyTypeInterface::schemaMetatagClient
PropertyTypeBase::schemaMetatagManager public function The Schema Metatag Manager service. Overrides PropertyTypeInterface::schemaMetatagManager
PropertyTypeBase::setPropertyTypeManager public function Sets PropertyTypeManager service.
PropertyTypeBase::setSchemaMetatagClient public function Sets SchemaMetatagClient service.
PropertyTypeBase::setSchemaMetatagManager public function Sets schemaMetatagManager service.
PropertyTypeBase::testDefaultValue public function Provide a random test value. Overrides SchemaMetatagTestTagInterface::testDefaultValue
PropertyTypeBase::validateProperty public static function Validates the property form when submitted. Overrides PropertyTypeInterface::validateProperty
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.