You are here

protected function ImagePopupFieldFormatter::getText in Simple Image Popup 2.x

Gets the text needed for alt and title text based on configuration.

This will only behave properly if $this->parent is set to the parent entity of this field.

Return value

string The text.

1 call to ImagePopupFieldFormatter::getText()
ImagePopupFieldFormatter::viewElements in src/Plugin/Field/FieldFormatter/ImagePopupFieldFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/ImagePopupFieldFormatter.php, line 321

Class

ImagePopupFieldFormatter
Plugin implementation of the 'image_popup_field_formatter' formatter.

Namespace

Drupal\image_popup\Plugin\Field\FieldFormatter

Code

protected function getText($base_field_id, $type) {
  $source = $this
    ->getSetting("{$base_field_id}_{$type}_source");
  if ($source === 'static') {

    // If the source is static, get the static value.
    return $this
      ->getSetting("{$base_field_id}_{$type}_static");
  }
  elseif ($source === 'field') {

    // If the source is a field, get that field's value from the parent.
    if (isset($this->parent)) {
      $field = $this
        ->getSetting("{$base_field_id}_{$type}_field");
      return $this->parent->{$field}->value;
    }
  }
  return '';
}