You are here

class SchemaItemListElementBreadcrumbBase in Schema.org Metatag 7

All Schema.org Breadcrumb tags should extend this class.

Hierarchy

Expanded class hierarchy of SchemaItemListElementBreadcrumbBase

1 string reference to 'SchemaItemListElementBreadcrumbBase'
schema_web_page_metatag_info in schema_web_page/schema_web_page.metatag.inc
Implements hook_metatag_info().

File

src/SchemaItemListElementBreadcrumbBase.php, line 6

View source
class SchemaItemListElementBreadcrumbBase extends SchemaItemListElementBase {

  /**
   * {@inheritdoc}
   */
  public function getForm(array $options = []) {
    $form['value'] = [
      '#type' => 'select',
      '#title' => $this
        ->label(),
      '#default_value' => $this
        ->value(),
      '#empty_option' => $this
        ->t('No'),
      '#empty_value' => '',
      '#options' => [
        'Yes' => $this
          ->t('Yes'),
      ],
      '#description' => $this
        ->description(),
    ];

    // Validation from parent::getForm() got wiped out, so add callback.
    $form['value']['#element_validate'][] = 'schema_metatag_element_validate';
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public static function testValue() {
    return 'Yes';
  }

  /**
   * {@inheritdoc}
   */
  public static 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 static function getItems($input_value) {
    $values = [];
    if (!empty($input_value)) {
      $breadcrumbs = drupal_get_breadcrumb();

      // Methods on DrupalDefaultMetaTag can't be called statically, and we
      // can't use $this from a static method, so create an empty instance.
      $data = $info = [];
      $processor = new DrupalDefaultMetaTag($data, $info);
      $key = 1;
      foreach ($breadcrumbs as $item) {
        $text = strip_tags($item);
        $url = '';
        $matches = [];
        if (preg_match('/href="([^"]*)"/', $item, $matches)) {
          if (!empty($matches[1])) {
            $url = $matches[1];
            $url = $processor
              ->convertUrlToAbsolute($url);
          }
        }
        $values[$key] = [
          '@id' => $url,
          'name' => $text,
          'item' => $url,
        ];
        $key++;
      }
    }
    return $values;
  }

}

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
SchemaItemListElementBreadcrumbBase::getForm public function Build the form for this meta tag. Overrides SchemaItemListElementBase::getForm
SchemaItemListElementBreadcrumbBase::getItems public static function Process the input value into an array of items. Overrides SchemaItemListElementBase::getItems
SchemaItemListElementBreadcrumbBase::outputValue public static function Transform input value to its display output. Overrides SchemaItemListElementBase::outputValue
SchemaItemListElementBreadcrumbBase::testValue public static function Provide a test input value for the property that will validate. Overrides SchemaItemListElementBase::testValue
SchemaNameBase::$schemaMetatagManager protected property The schemaMetatagManager service.
SchemaNameBase::description public function
SchemaNameBase::getElement public function Get the HTML tag for this meta tag. Overrides DrupalDefaultMetaTag::getElement 1
SchemaNameBase::getPluginId public function
SchemaNameBase::label public function
SchemaNameBase::multiple public function
SchemaNameBase::neverExplode public static function Nested elements that cannot be exploded.
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::value public function
SchemaNameBase::visibilitySelector protected function The #states visibility selector for this element.
SchemaNameBase::__construct function Constructor. Overrides DrupalDefaultMetaTag::__construct 1