You are here

public function LinkNoText::viewElements in ShrinkTheWeb 8

Builds a renderable array for a field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.

string $langcode: The language that should be used to render the field.

Return value

array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.

Overrides FormatterInterface::viewElements

File

src/Plugin/Field/FieldFormatter/LinkNoText.php, line 179

Class

LinkNoText
Plugin annotation @FieldFormatter( id = "shrinktheweb_link_no_text", label = @Translation("[ShrinkTheWeb] No link text"), field_types = {"link"} )

Namespace

Drupal\shrinktheweb\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $settings = $this
    ->getSettings();
  $elements = array();
  foreach ($items as $delta => $item) {
    $url = $item->uri;
    $elements[$delta] = array(
      '#theme' => 'shrinktheweb_image',
      '#url' => $url,
      '#image_path' => '',
    );
    if (!empty($settings['custom_width'])) {
      $elements[$delta]['#custom_width'] = $settings['custom_width'];
    }
    if (!empty($settings['full_length'])) {
      $elements[$delta]['#full_length'] = $settings['full_length'];
    }
    if (!empty($settings['max_height'])) {
      $elements[$delta]['#max_height'] = $settings['max_height'];
    }
    if (!empty($settings['native_resolution'])) {
      $elements[$delta]['#native_resolution'] = $settings['native_resolution'];
    }
    if (!empty($settings['widescreen_resolution_y'])) {
      $elements[$delta]['#widescreen_resolution_y'] = $settings['widescreen_resolution_y'];
    }
    if (!empty($settings['delay'])) {
      $elements[$delta]['#delay'] = $settings['delay'];
    }
    if (!empty($settings['quality'])) {
      $elements[$delta]['#quality'] = $settings['quality'];
    }
  }
  return $elements;
}