You are here

class SchemaTypeBase in Schema.org Metatag 8

Provides a plugin for the 'schema_type_base' meta tag.

Hierarchy

Expanded class hierarchy of SchemaTypeBase

23 files declare their use of SchemaTypeBase
SchemaArticleType.php in schema_article/src/Plugin/metatag/Tag/SchemaArticleType.php
SchemaBookType.php in schema_book/src/Plugin/metatag/Tag/SchemaBookType.php
SchemaCourseType.php in schema_course/src/Plugin/metatag/Tag/SchemaCourseType.php
SchemaEventType.php in schema_event/src/Plugin/metatag/Tag/SchemaEventType.php
SchemaHowToType.php in schema_how_to/src/Plugin/metatag/Tag/SchemaHowToType.php

... See full list

File

src/Plugin/metatag/Tag/SchemaTypeBase.php, line 8

Namespace

Drupal\schema_metatag\Plugin\metatag\Tag
View source
class SchemaTypeBase extends SchemaNameBase {

  /**
   * Return a list of object labels.
   *
   * This is generally the only method that needs to be extended for type tags.
   * Either return a simple array of types, or prefix the type names with dashes
   * and spaces to indicate their hierarchy. The prefixed dashes and spaces will
   * be removed when creating the raw list of available types.
   *
   * @see SchemaOrganizationType::labels()
   */
  public static function labels() {
    return [
      'Organization',
    ];
  }

  /**
   * Generate a form element for this meta tag.
   */
  public function form(array $element = []) {
    $form = [
      '#type' => 'select',
      '#title' => $this
        ->label(),
      '#description' => $this
        ->description(),
      '#empty_option' => $this
        ->t('- None -'),
      '#empty_value' => '',
      '#options' => $this
        ->typeOptions(),
      '#default_value' => $this
        ->value(),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public static function testValue() {
    $types = static::types();
    return array_shift($types);
  }

  /**
   * Return a list of object types.
   */
  public static function types() {
    $labels = static::labels();
    return array_map('static::removePrefix', $labels);
  }

  /**
   * Turn the list of types into an option list.
   */
  public function typeOptions() {
    $types = static::types();
    $labels = static::labels();
    return array_combine($types, $labels);
  }

  /**
   * Clean up a list of labels by removing leading spaces and dashes.
   */
  public static function removePrefix($item) {
    return str_replace([
      '-',
      ' ',
    ], '', $item);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MetaNameBase::$absoluteUrl protected property True if the URL value(s) must be absolute.
MetaNameBase::$description protected property A longer explanation of what the field is for.
MetaNameBase::$group protected property The category this meta tag fits in.
MetaNameBase::$id protected property Machine name of the meta tag plugin.
MetaNameBase::$label protected property The title of the plugin.
MetaNameBase::$long protected property True if the tag should use a text area.
MetaNameBase::$multiple protected property True if more than one is allowed.
MetaNameBase::$name protected property Official metatag name. 1
MetaNameBase::$nameAttribute protected property The attribute this tag uses for the name. 3
MetaNameBase::$request protected property Retrieves the currently active request object.
MetaNameBase::$secure protected property True if URL must use HTTPS.
MetaNameBase::$type protected property Type of the value being stored.
MetaNameBase::$value protected property The value of the metatag in this instance.
MetaNameBase::description public function The meta tag's description.
MetaNameBase::group public function The meta tag group this meta tag belongs to.
MetaNameBase::id public function Obtain the meta tag's internal ID.
MetaNameBase::isActive public function Whether or not this meta tag is active.
MetaNameBase::isLong public function Whether or not this meta tag should use a text area.
MetaNameBase::label public function This meta tag's label.
MetaNameBase::multiple public function Whether or not this meta tag supports multiple values.
MetaNameBase::name public function The meta tag's machine name. 1
MetaNameBase::parseImageUrl protected function Extract any image URLs that might be found in a meta tag.
MetaNameBase::requiresAbsoluteUrl public function Whether or not this meta tag must output required absolute URLs.
MetaNameBase::secure public function Whether or not this meta tag must output secure (HTTPS) URLs.
MetaNameBase::tidy private function Make the string presentable.
MetaNameBase::type public function Obtain this meta tag's type.
MetaNameBase::validateTag public static function Validates the metatag data.
MetaNameBase::weight public function This meta tag's form field's weight.
MetaNameBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
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.
SchemaNameBase::$schemaMetatagManager protected property The schemaMetatagManager service.
SchemaNameBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
SchemaNameBase::neverExplode protected function Nested elements that cannot be exploded.
SchemaNameBase::output public function Generate the HTML tag output for a meta tag. Overrides MetaNameBase::output 1
SchemaNameBase::outputValue public static function Transform input value to its display output. Overrides SchemaMetatagTestTagInterface::outputValue 2
SchemaNameBase::parseImageUrlValue protected function Parse the image url out of image markup.
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
SchemaNameBase::processTestExplodeValue public static function Explode a test value. Overrides SchemaMetatagTestTagInterface::processTestExplodeValue
SchemaNameBase::schemaMetatagManager protected function Return the SchemaMetatagManager.
SchemaNameBase::setSchemaMetatagManager public function Sets schemaMetatagManager service.
SchemaNameBase::setValue public function Metatag expects a string value, so serialize any array of values. Overrides MetaNameBase::setValue
SchemaNameBase::testDefaultValue public static function Provide a random test value. Overrides SchemaMetatagTestTagInterface::testDefaultValue
SchemaNameBase::value public function The serialized value for the metatag. Overrides MetaNameBase::value
SchemaNameBase::visibilitySelector protected function The #states base visibility selector for this element.
SchemaTypeBase::form public function Generate a form element for this meta tag. Overrides MetaNameBase::form
SchemaTypeBase::labels public static function Return a list of object labels. 23
SchemaTypeBase::removePrefix public static function Clean up a list of labels by removing leading spaces and dashes.
SchemaTypeBase::testValue public static function Provide a test input value for the property that will validate. Overrides SchemaNameBase::testValue
SchemaTypeBase::typeOptions public function Turn the list of types into an option list.
SchemaTypeBase::types public static function Return a list of object types.
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.