You are here

private function CdnProvider::createProviderGroup in Express 8

Creates the necessary containers for each provider.

Parameters

\Drupal\bootstrap\Utility\Element $group: The group element instance.

\Drupal\bootstrap\Plugin\Provider\ProviderInterface $provider: The provider instance.

1 call to CdnProvider::createProviderGroup()
CdnProvider::alterFormElement in themes/contrib/bootstrap/src/Plugin/Setting/Advanced/Cdn/CdnProvider.php
The alter method to store the code.

File

themes/contrib/bootstrap/src/Plugin/Setting/Advanced/Cdn/CdnProvider.php, line 114
Contains \Drupal\bootstrap\Plugin\Setting\Advanced\Cdn\CdnProvider.

Class

CdnProvider
The "cdn_provider" theme setting.

Namespace

Drupal\bootstrap\Plugin\Setting\Advanced\Cdn

Code

private function createProviderGroup(Element $group, ProviderInterface $provider) {
  $plugin_id = Html::cleanCssIdentifier($provider
    ->getPluginId());

  // Create the provider container.
  $group->{$plugin_id} = [
    '#type' => 'container',
    '#prefix' => '<div id="cdn-provider-' . $plugin_id . '">',
    '#suffix' => '</div>',
    '#states' => [
      'visible' => [
        ':input[name="cdn_provider"]' => [
          'value' => $plugin_id,
        ],
      ],
    ],
  ];

  // Add in the provider description.
  if ($description = $provider
    ->getDescription()) {
    $group->{$plugin_id}->description = [
      '#markup' => '<div class="lead">' . $description . '</div>',
      '#weight' => -99,
    ];
  }

  // Indicate there was an error retrieving the provider's API data.
  if ($provider
    ->hasError() || $provider
    ->isImported()) {
    if ($provider
      ->hasError()) {
      $group->{$plugin_id}->error = [
        '#markup' => '<div class="alert alert-danger messages error"><strong>' . t('ERROR') . ':</strong> ' . t('Unable to reach or parse the data provided by the @title API. Ensure the server this website is hosted on is able to initiate HTTP requests. If the request consistently fails, it is likely that there are certain PHP functions that have been disabled by the hosting provider for security reasons. It is possible to manually copy and paste the contents of the following URL into the "Imported @title data" section below.<br /><br /><a href=":provider_api" target="_blank">:provider_api</a>.', [
          '@title' => $provider
            ->getLabel(),
          ':provider_api' => $provider
            ->getApi(),
        ]) . '</div>',
        '#weight' => -20,
      ];
    }
    $group->{$plugin_id}->import = [
      '#type' => 'details',
      '#title' => t('Imported @title data', [
        '@title' => $provider
          ->getLabel(),
      ]),
      '#description' => t('The provider will attempt to parse the data entered here each time it is saved. If no data has been entered, any saved files associated with this provider will be removed and the provider will again attempt to request the API data normally through the following URL: <a href=":provider_api" target="_blank">:provider_api</a>.', [
        ':provider_api' => $provider
          ->getPluginDefinition()['api'],
      ]),
      '#weight' => 10,
      '#open' => FALSE,
    ];
    $group->{$plugin_id}->import->cdn_provider_import_data = [
      '#type' => 'textarea',
      '#default_value' => file_exists(ProviderManager::FILE_PATH . '/' . $plugin_id . '.json') ? file_get_contents(ProviderManager::FILE_PATH . '/' . $plugin_id . '.json') : NULL,
    ];
    $group->{$plugin_id}->import->submit = [
      '#type' => 'submit',
      '#value' => t('Save provider data'),
      '#executes_submit_callback' => FALSE,
      '#ajax' => [
        'callback' => [
          get_class($this),
          'ajaxCallback',
        ],
        'wrapper' => 'cdn-provider-' . $plugin_id,
      ],
    ];
  }
}