You are here

public function BlazyEntity::getFieldValue in Blazy 8.2

Same name and namespace in other branches
  1. 7 src/BlazyEntity.php \Drupal\blazy\BlazyEntity::getFieldValue()

Returns the string value of the fields: link, or text.

2 calls to BlazyEntity::getFieldValue()
BlazyEntity::getFieldString in src/BlazyEntity.php
Returns the string value of the fields: link, or text.
BlazyEntity::getFieldTextOrLink in src/BlazyEntity.php
Returns the text or link value of the fields: link, or text.

File

src/BlazyEntity.php, line 168

Class

BlazyEntity
Provides common entity utilities to work with field details.

Namespace

Drupal\blazy

Code

public function getFieldValue($entity, $field_name, $langcode) {
  if ($entity
    ->hasField($field_name)) {
    if ($entity
      ->hasTranslation($langcode)) {

      // If the entity has translation, fetch the translated value.
      return $entity
        ->getTranslation($langcode)
        ->get($field_name)
        ->getValue();
    }

    // Entity doesn't have translation, fetch original value.
    return $entity
      ->get($field_name)
      ->getValue();
  }
  return NULL;
}