You are here

public function LdapVariableImageAttribute::render in Lightweight Directory Access Protocol (LDAP) 8.4

Same name and namespace in other branches
  1. 8.3 ldap_query/src/Plugin/views/field/LdapVariableImageAttribute.php \Drupal\ldap_query\Plugin\views\field\LdapVariableImageAttribute::render()

Encodes a binary image for display directly in Views.

Parameters

\Drupal\views\ResultRow $values: Result row.

Return value

array|null Markup with image if available.

Overrides LdapAttribute::render

File

ldap_query/src/Plugin/views/field/LdapVariableImageAttribute.php, line 29

Class

LdapVariableImageAttribute
Let's the user choose which LDAP attribute to use from the query.

Namespace

Drupal\ldap_query\Plugin\views\field

Code

public function render(ResultRow $values) : array {
  $formatter = '';
  if ($this
    ->getValue($values)) {
    $data = $this
      ->getValue($values)[0];
    $formatter = new FormattableMarkup('<img src="data:image/jpeg;base64,:src"/>', [
      ':src' => base64_encode($data),
    ]);
  }
  return [
    '#markup' => $formatter,
  ];
}