class SchemaNameBase in Schema.org Metatag 8
Same name and namespace in other branches
- 8.2 src/Plugin/metatag/Tag/SchemaNameBase.php \Drupal\schema_metatag\Plugin\metatag\Tag\SchemaNameBase
All Schema.org tags should extend this class.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\metatag\Plugin\metatag\Tag\MetaNameBase uses StringTranslationTrait
- class \Drupal\schema_metatag\Plugin\metatag\Tag\SchemaNameBase implements ContainerFactoryPluginInterface, SchemaMetatagTestTagInterface
- class \Drupal\metatag\Plugin\metatag\Tag\MetaNameBase uses StringTranslationTrait
Expanded class hierarchy of SchemaNameBase
119 files declare their use of SchemaNameBase
- SchemaArticleAbout.php in schema_article/
src/ Plugin/ metatag/ Tag/ SchemaArticleAbout.php - SchemaArticleAgeRange.php in schema_article_example/
src/ Plugin/ metatag/ Tag/ SchemaArticleAgeRange.php - SchemaArticleDescription.php in schema_article/
src/ Plugin/ metatag/ Tag/ SchemaArticleDescription.php - SchemaArticleHeadline.php in schema_article/
src/ Plugin/ metatag/ Tag/ SchemaArticleHeadline.php - SchemaArticleName.php in schema_article/
src/ Plugin/ metatag/ Tag/ SchemaArticleName.php
3 string references to 'SchemaNameBase'
- SchemaActionTrait::actionProperties in src/
Plugin/ metatag/ Tag/ SchemaActionTrait.php - Return an array of the unique properties for an action type.
- SchemaCreativeWorkTrait::creativeWorkProperties in src/
Plugin/ metatag/ Tag/ SchemaCreativeWorkTrait.php - Return an array of the unique properties for an object type.
- SchemaHasPartTrait::hasPartProperties in src/
Plugin/ metatag/ Tag/ SchemaHasPartTrait.php - Return an array of the unique properties for an object type.
File
- src/
Plugin/ metatag/ Tag/ SchemaNameBase.php, line 14
Namespace
Drupal\schema_metatag\Plugin\metatag\TagView source
class SchemaNameBase extends MetaNameBase implements SchemaMetatagTestTagInterface, ContainerFactoryPluginInterface {
/**
* The schemaMetatagManager service.
*
* @var \Drupal\schema_metatag\schemaMetatagManager
*/
protected $schemaMetatagManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = new static($configuration, $plugin_id, $plugin_definition);
$instance
->setSchemaMetatagManager($container
->get('schema_metatag.schema_metatag_manager'));
return $instance;
}
/**
* Sets schemaMetatagManager service.
*
* @param \Drupal\schema_metatag\SchemaMetatagManager $schemaMetatagManager
* The Schema Metatag Manager service.
*/
public function setSchemaMetatagManager(SchemaMetatagManager $schemaMetatagManager) {
$this->schemaMetatagManager = $schemaMetatagManager;
}
/**
* Return the SchemaMetatagManager.
*
* @return \Drupal\schema_metatag\SchemaMetatagManager
* The Schema Metatag Manager service.
*/
protected function schemaMetatagManager() {
return $this->schemaMetatagManager;
}
/**
* The #states base visibility selector for this element.
*/
protected function visibilitySelector() {
return $this
->getPluginId();
}
/**
* {@inheritdoc}
*/
public function output() {
$value = $this
->schemaMetatagManager()
->unserialize($this
->value());
// If this is a complex array of value, 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 = static::pivotItem($value);
}
else {
$this
->processItem($value);
}
$output = [
'#tag' => 'meta',
'#attributes' => [
'name' => $this->name,
'content' => static::outputValue($value),
'group' => $this->group,
'schema_metatag' => TRUE,
],
];
return $output;
}
/**
* The serialized value for the metatag.
*
* Metatag expects a string value, so use the serialized value
* without unserializing it. Manually unserialize it when needed.
*/
public function value() {
return $this->value;
}
/**
* Metatag expects a string value, so serialize any array of values.
*/
public function setValue($value) {
$this->value = $this
->schemaMetatagManager()
->serialize($value);
}
/**
* {@inheritdoc}
*/
public static function pivotItem($array) {
// See if any nested items need to be pivoted.
// If pivot is set to 0, it would have been removed as an empty value.
if (array_key_exists('pivot', $array)) {
unset($array['pivot']);
/** @var \Drupal\schema_metatag\SchemaMetatagManagerInterface $schemaMetatagManager */
$schemaMetatagManager = \Drupal::service('schema_metatag.schema_metatag_manager');
$array = $schemaMetatagManager
->pivot($array);
}
foreach ($array as &$value) {
if (is_array($value)) {
$value = static::pivotItem($value);
}
}
return $array;
}
/**
* Nested elements that cannot be exploded.
*
* @return array
* Array of keys that might contain commas, or otherwise cannot be exploded.
*/
protected function neverExplode() {
return [
'streetAddress',
'reviewBody',
'recipeInstructions',
];
}
/**
* {@inheritdoc}
*/
protected function processItem(&$value, $key = 0) {
$explode = $key === 0 ? $this
->multiple() : !in_array($key, $this
->neverExplode());
// Parse out the image URL, if needed.
$value = $this
->parseImageUrlValue($value, $explode);
$value = trim($value);
// If tag must be secure, convert all http:// to https://.
if ($this
->secure() && strpos($value, 'http://') !== FALSE) {
$value = str_replace('http://', 'https://', $value);
}
if ($explode) {
$value = $this
->schemaMetatagManager()
->explode($value);
// Clean out any empty values that might have been added by explode().
if (is_array($value)) {
$value = array_filter($value);
}
}
}
/**
* Parse the image url out of image markup.
*
* A copy of the base method of the same name, but where $value is passed
* in instead of assumed to be $this->value().
*/
protected function parseImageUrlValue($value, $explode) {
// If this contains embedded image tags, extract the image URLs.
if ($this
->type() === 'image') {
// If image tag src is relative (starts with /), convert to an absolute
// link.
global $base_root;
if (strpos($value, '<img src="/') !== FALSE) {
$value = str_replace('<img src="/', '<img src="' . $base_root . '/', $value);
}
if (strip_tags($value) != $value) {
if ($explode) {
$values = explode(',', $value);
}
else {
$values = [
$value,
];
}
// Check through the value(s) to see if there are any image tags.
foreach ($values as $key => $val) {
$matches = [];
preg_match('/src="([^"]*)"/', $val, $matches);
if (!empty($matches[1])) {
$values[$key] = $matches[1];
}
}
$value = implode(',', $values);
// Remove any HTML tags that might remain.
$value = strip_tags($value);
}
}
return $value;
}
/**
* {@inheritdoc}
*/
public static function outputValue($input_value) {
return $input_value;
}
/**
* {@inheritdoc}
*/
public static function testValue() {
return static::testDefaultValue(2, ' ');
}
/**
* {@inheritdoc}
*/
public static function processedTestValue($items) {
return $items;
}
/**
* {@inheritdoc}
*/
public static function processTestExplodeValue($items) {
if (!is_array($items)) {
// Call this value statically for static test value.
$items = SchemaMetatagManager::explode($items);
// Clean out any empty values that might have been added by explode().
if (is_array($items)) {
array_filter($items);
}
}
return $items;
}
/**
* {@inheritdoc}
*/
public static function testDefaultValue($count = NULL, $delimiter = NULL) {
$items = [];
$min = 1;
$max = isset($count) ? $count : 2;
$delimiter = isset($delimiter) ? $delimiter : ' ';
for ($i = $min; $i <= $max; $i++) {
// Call this value statically for static test value.
$items[] = SchemaMetatagManager::randomMachineName();
}
return implode($delimiter, $items);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MetaNameBase:: |
protected | property | True if the URL value(s) must be absolute. | |
MetaNameBase:: |
protected | property | A longer explanation of what the field is for. | |
MetaNameBase:: |
protected | property | The category this meta tag fits in. | |
MetaNameBase:: |
protected | property | Machine name of the meta tag plugin. | |
MetaNameBase:: |
protected | property | The title of the plugin. | |
MetaNameBase:: |
protected | property | True if the tag should use a text area. | |
MetaNameBase:: |
protected | property | True if more than one is allowed. | |
MetaNameBase:: |
protected | property | Official metatag name. | 1 |
MetaNameBase:: |
protected | property | The attribute this tag uses for the name. | 3 |
MetaNameBase:: |
protected | property | Retrieves the currently active request object. | |
MetaNameBase:: |
protected | property | True if URL must use HTTPS. | |
MetaNameBase:: |
protected | property | Type of the value being stored. | |
MetaNameBase:: |
protected | property | The value of the metatag in this instance. | |
MetaNameBase:: |
public | function | The meta tag's description. | |
MetaNameBase:: |
public | function | Generate a form element for this meta tag. | 6 |
MetaNameBase:: |
public | function | The meta tag group this meta tag belongs to. | |
MetaNameBase:: |
public | function | Obtain the meta tag's internal ID. | |
MetaNameBase:: |
public | function | Whether or not this meta tag is active. | |
MetaNameBase:: |
public | function | Whether or not this meta tag should use a text area. | |
MetaNameBase:: |
public | function | This meta tag's label. | |
MetaNameBase:: |
public | function | Whether or not this meta tag supports multiple values. | |
MetaNameBase:: |
public | function | The meta tag's machine name. | 1 |
MetaNameBase:: |
protected | function | Extract any image URLs that might be found in a meta tag. | |
MetaNameBase:: |
public | function | Whether or not this meta tag must output required absolute URLs. | |
MetaNameBase:: |
public | function | Whether or not this meta tag must output secure (HTTPS) URLs. | |
MetaNameBase:: |
private | function | Make the string presentable. | |
MetaNameBase:: |
public | function | Obtain this meta tag's type. | |
MetaNameBase:: |
public static | function | Validates the metatag data. | |
MetaNameBase:: |
public | function | This meta tag's form field's weight. | |
MetaNameBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
SchemaNameBase:: |
protected | property | The schemaMetatagManager service. | |
SchemaNameBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
SchemaNameBase:: |
protected | function | Nested elements that cannot be exploded. | |
SchemaNameBase:: |
public | function |
Generate the HTML tag output for a meta tag. Overrides MetaNameBase:: |
1 |
SchemaNameBase:: |
public static | function |
Transform input value to its display output. Overrides SchemaMetatagTestTagInterface:: |
2 |
SchemaNameBase:: |
protected | function | Parse the image url out of image markup. | |
SchemaNameBase:: |
public static | function | ||
SchemaNameBase:: |
public static | function |
Provide a test output value for the input value. Overrides SchemaMetatagTestTagInterface:: |
17 |
SchemaNameBase:: |
protected | function | ||
SchemaNameBase:: |
public static | function |
Explode a test value. Overrides SchemaMetatagTestTagInterface:: |
|
SchemaNameBase:: |
protected | function | Return the SchemaMetatagManager. | |
SchemaNameBase:: |
public | function | Sets schemaMetatagManager service. | |
SchemaNameBase:: |
public | function |
Metatag expects a string value, so serialize any array of values. Overrides MetaNameBase:: |
|
SchemaNameBase:: |
public static | function |
Provide a random test value. Overrides SchemaMetatagTestTagInterface:: |
|
SchemaNameBase:: |
public static | function |
Provide a test input value for the property that will validate. Overrides SchemaMetatagTestTagInterface:: |
30 |
SchemaNameBase:: |
public | function |
The serialized value for the metatag. Overrides MetaNameBase:: |
|
SchemaNameBase:: |
protected | function | The #states base visibility selector for this element. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |