You are here

public function ProvidersController::providers in Persistent URL 8

1 string reference to 'ProvidersController::providers'
purl.routing.yml in ./purl.routing.yml
purl.routing.yml

File

src/Controller/ProvidersController.php, line 64

Class

ProvidersController

Namespace

Drupal\purl\Controller

Code

public function providers(Request $request) {
  $methods = array(
    '' => sprintf('-- %s --', t('Disabled')),
  );
  foreach ($this->methodManager
    ->getDefinitions() as $definition) {
    $methods[$definition['id']] = $definition['name'];
  }
  $providers = array();
  $defaultConfig = array(
    'method' => null,
    'settings' => array(),
  );
  $headers = array(
    'providers',
    'methods',
    'settings',
  );
  $rows = array();
  foreach ($this->providerManager
    ->getDefinitions() as $id => $definition) {
    $row = array(
      array(
        'data' => $definition['name'],
      ),
      array(
        'data' => array(
          '#theme' => 'select',
          '#value' => $definition['method'],
          '#options' => $methods,
          '#name' => sprintf('providers[%s][method]', $id),
        ),
      ),
      array(
        'data' => '',
      ),
    );
    $rows[] = $row;
  }
  $tableData = array(
    '#theme' => 'table',
    '#header' => array_map(function ($header) {
      return array(
        'data' => t($header),
      );
    }, $headers),
    '#rows' => $rows,
  );
  $build = array();
  $build['providers_settings_form'] = array(
    '#type' => 'html_tag',
    '#tag' => 'form',
    '#attributes' => array(
      'method' => 'POST',
      'action' => \Drupal::url('purl.admin.save_providers_config'),
    ),
  );
  $submitData = array(
    '#type' => 'html_tag',
    '#tag' => 'input',
    '#attributes' => array(
      'class' => array(
        'button button--primary form-submit',
      ),
      'type' => 'submit',
      'value' => 'Save',
    ),
  );
  $formContents = array(
    'table' => $tableData,
    'submit' => $submitData,
  );
  $form = drupal_render($formContents);
  $build['providers_settings_form']['#value'] = $form;
  return $build;
}