class MetatagQuery in GatherContent 8.4
Same name and namespace in other branches
- 8.5 src/MetatagQuery.php \Drupal\gathercontent\MetatagQuery
Class for querying metatag data.
Hierarchy
- class \Drupal\gathercontent\MetatagQuery implements ContainerInjectionInterface
Expanded class hierarchy of MetatagQuery
2 files declare their use of MetatagQuery
- ContentProcessor.php in src/
Import/ ContentProcess/ ContentProcessor.php - GcImportTestBase.php in tests/
src/ Kernel/ GcImportTestBase.php
1 string reference to 'MetatagQuery'
1 service uses MetatagQuery
File
- src/
MetatagQuery.php, line 12
Namespace
Drupal\gathercontentView source
class MetatagQuery implements ContainerInjectionInterface {
protected $entityFieldManager;
/**
* MetatagQuery constructor.
*/
public function __construct(EntityFieldManagerInterface $entityFieldManager) {
$this->entityFieldManager = $entityFieldManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_field.manager'));
}
/**
* Check if content type has any metatag fields.
*
* @param string $content_type
* Machine name of content type.
*
* @return bool
* TRUE if metatag field exists.
*/
public function checkMetatag($content_type) {
$instances = $this->entityFieldManager
->getFieldDefinitions('node', $content_type);
foreach ($instances as $name => $instance) {
/** @var \Drupal\Core\Field\FieldDefinitionInterface $instance */
if ($instance
->getType() === 'metatag') {
return TRUE;
}
}
return FALSE;
}
/**
* Get list of metatag fields.
*
* @param string $content_type
* Machine name of content type.
*
* @return array
* Array of metatag fields.
*/
public function getMetatagFields($content_type) {
$instances = $this->entityFieldManager
->getFieldDefinitions('node', $content_type);
$fields = [];
foreach ($instances as $name => $instance) {
/** @var \Drupal\Core\Field\FieldDefinitionInterface $instance */
if ($instance
->getType() === 'metatag') {
$fields[] = $instance
->getName();
}
}
return $fields;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MetatagQuery:: |
protected | property | ||
MetatagQuery:: |
public | function | Check if content type has any metatag fields. | |
MetatagQuery:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
MetatagQuery:: |
public | function | Get list of metatag fields. | |
MetatagQuery:: |
public | function | MetatagQuery constructor. |