You are here

public function SeoManager::getSeoField in Real-time SEO for Drupal 8.2

Returns the Real-Time SEO field of the entity.

Returns the first field of the entity that is a Real-Time SEO field or null if none is found.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity for which to find the Real-Time SEO field.

Return value

null|\Drupal\Core\Field\FieldItemListInterface The field item list of the field or NULL if no RTSEO field was found.

File

src/SeoManager.php, line 107

Class

SeoManager
Utility service for the Real-Time SEO module.

Namespace

Drupal\yoast_seo

Code

public function getSeoField(FieldableEntityInterface $entity) {
  $definitions = $entity
    ->getFieldDefinitions();

  // Find the first yoast_seo field on the entity.
  foreach ($definitions as $definition) {
    if ($definition
      ->getType() === 'yoast_seo') {
      return $entity
        ->get($definition
        ->getName());
    }
  }

  // No field of yoast_seo type was found.
  return NULL;
}