SimplesamlphpCustomAttributesController.php in SimpleSAMLphp Custom Attribute Mapping 8
File
src/Controller/SimplesamlphpCustomAttributesController.php
View source
<?php
namespace Drupal\simplesamlphp_custom_attributes\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SimplesamlphpCustomAttributesController extends ControllerBase {
protected $mappingConfig;
protected $entityFieldManager;
public function __construct(EntityFieldManagerInterface $entity_field_manager) {
$this->mappingConfig = $this
->config('simplesamlphp_custom_attributes.mappings');
$this->entityFieldManager = $entity_field_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_field.manager'));
}
public function ssoMappings() {
$mappings = $this->mappingConfig
->get('mappings');
$fields = $this->entityFieldManager
->getFieldDefinitions('user', 'user');
$table = [
'#theme' => 'table',
'#header' => [
$this
->t('SAML Attribute'),
$this
->t('User Field'),
$this
->t('Operations'),
],
'#sticky' => TRUE,
'#empty' => $this
->t("There are no mappings. You can add one using the link above."),
];
if ($mappings) {
foreach ($mappings as $id => $mapping) {
if ($mapping['field_name'] === 'custom') {
$user_field = $this
->t('Custom');
}
else {
if (isset($fields[$mapping['field_name']])) {
$user_field = $fields[$mapping['field_name']]
->getLabel();
}
else {
$user_field = $this
->t('Missing field: %field', [
'%field' => $mapping['field_name'],
]);
}
}
$operations = [
'#type' => 'dropbutton',
'#links' => [
'edit' => [
'title' => $this
->t('edit'),
'url' => Url::fromRoute('simplesamlphp_custom_attributes.edit', [
'mapping' => $id,
]),
],
'delete' => [
'title' => $this
->t('delete'),
'url' => Url::fromRoute('simplesamlphp_custom_attributes.delete', [
'mapping' => $id,
]),
],
],
];
$table['#rows'][$id] = [
'saml_attribute' => $mapping['attribute_name'],
'user_field' => $user_field,
'operations' => render($operations),
];
}
}
return $table;
}
}