LdapVariableImageAttribute.php in Lightweight Directory Access Protocol (LDAP) 8.4
File
ldap_query/src/Plugin/views/field/LdapVariableImageAttribute.php
View source
<?php
declare (strict_types=1);
namespace Drupal\ldap_query\Plugin\views\field;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ResultRow;
class LdapVariableImageAttribute extends LdapVariableAttribute {
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,
];
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) : void {
parent::buildOptionsForm($form, $form_state);
unset($form['multi_value']);
unset($form['value_separator']);
unset($form['index_value']);
}
}