julianmancera → created an issue.
julianmancera → created an issue.
Hi all,
I found a workaround for the issue, our case we use a preprocess function to set some html tag attributes within a views render array, when these attributes were rendered the object vs array error popup, next the workaround:
$group_row_attributes = new Attribute();
$group_row_attributes->setAttribute('class', $index == 0 ? 'nav-link active' : 'nav-link');
$group_row_attributes->setAttribute('id', "$category_name_id-tab");
$group_row_attributes->setAttribute('data-toggle', 'pill');
$group_row_attributes->setAttribute('href', "#$category_name_id");
$group_row_attributes->setAttribute('role', 'tab');
$group_row_attributes->setAttribute('aria-controls', $category_name_id);
$group_row_attributes->setAttribute('aria-selected', $index == 0 ? 'true' : 'false');
$variables['rows'][$index]['attributes'] = $group_row_attributes;
$variables['rows'][$index]['#pre_render'][] = function ($elements) {
unset($elements['attributes']);
return $elements;
};
So correct the issue we added the $variables['rows'][$index]['#pre_render'][] function to unset the attributes array after the preprocess function is ran in ThemeManager.php line 261 for preprocess function and the the prerender in the render service.
To accomplish this you can add an event subscriber to AUTHMAP_ALTER event like:
<?php
namespace Drupal\my_module\EventSubscriber;
use Drupal\Core\Database\Connection;
use Drupal\externalauth\Event\ExternalAuthAuthmapAlterEvent;
use Drupal\externalauth\Event\ExternalAuthEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class ExternalAuthSubscriber.
*
* @package Drupal\my_module\EventSubscriber
*/
class ExternalAuthSubscriber implements EventSubscriberInterface {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected Connection $database;
/**
* Constructor.
*
* We use dependency injection.
*
* @param \Drupal\Core\Database\Connection $database
* The database service.
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
// Static class constant => method on this class.
ExternalAuthEvents::AUTHMAP_ALTER => 'onUserRegisterMapAlter',
];
}
/**
* Subscribe to the external auth map event dispatched.
*
* @param \Drupal\externalauth\Event\ExternalAuthAuthmapAlterEvent $event
* Mapping event object.
*/
public function onUserRegisterMapAlter(ExternalAuthAuthmapAlterEvent $event) {
$account = $event->getAuthname();
// Looking for user email.
$query = $this->database->select('users_field_data', 'ufs')
->fields('ufs', ['name'])
->range(0, 1)
->condition('mail', $email)
->execute();
$user_account = $query->fetchObject();
if ($user_account) {
$event->setUsername($user_account->name);
}
}
}
Though some times you have different username that the authname, for such case you can use the patch attached
julianmancera → created an issue.
@borisson_ did you find how to integrate it?