You are here

class DeveloperSyncForm in Apigee Edge 8

Provides a form to start developer synchronization.

Hierarchy

Expanded class hierarchy of DeveloperSyncForm

1 string reference to 'DeveloperSyncForm'
apigee_edge.routing.yml in ./apigee_edge.routing.yml
apigee_edge.routing.yml

File

src/Form/DeveloperSyncForm.php, line 31

Namespace

Drupal\apigee_edge\Form
View source
class DeveloperSyncForm extends FormBase {

  /**
   * The SDK connector service.
   *
   * @var \Drupal\apigee_edge\SDKConnectorInterface
   */
  protected $sdkConnector;

  /**
   * Constructs a new DeveloperSyncForm.
   *
   * @param \Drupal\apigee_edge\SDKConnectorInterface $sdk_connector
   *   SDK connector service.
   */
  public function __construct(SDKConnectorInterface $sdk_connector) {
    $this->sdkConnector = $sdk_connector;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('apigee_edge.sdk_connector'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'apigee_edge_developer_sync_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    try {
      $this->sdkConnector
        ->testConnection();
    } catch (\Exception $exception) {
      $this
        ->messenger()
        ->addError($this
        ->t('Cannot connect to Apigee Edge server. Please ensure that <a href=":link">Apigee Edge connection settings</a> are correct.', [
        ':link' => Url::fromRoute('apigee_edge.settings')
          ->toString(),
      ]));
      return $form;
    }
    $form['#attached']['library'][] = 'apigee_edge/apigee_edge.admin';
    $form['sync'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Synchronize developers'),
      '#open' => TRUE,
    ];
    $form['sync']['description'] = [
      '#type' => 'container',
      'p1' => [
        '#type' => 'html_tag',
        '#tag' => 'p',
        '#value' => $this
          ->t('Developer synchronization will:'),
      ],
      'list' => [
        '#theme' => 'item_list',
        '#items' => [
          $this
            ->t('Create Drupal users for any Apigee Edge developers that are in this Drupal system'),
          $this
            ->t('Create developers in Apigee Edge for all users in this Drupal system that are not already in Apigee Edge'),
        ],
      ],
      'p2' => [
        '#type' => 'html_tag',
        '#tag' => 'p',
        '#value' => $this
          ->t('Note that any Drupal users that are created will have a random password generated and will need to reset their password to log in. The "Run developer sync" button will sync the developers, displaying a progress bar on the screen while running. The "Background developer sync" button will run the developer sync process in batches each time <a href=":cron_url">cron</a> runs and may take multiple cron runs to complete.', [
          ':cron_url' => Url::fromRoute('system.cron_settings')
            ->toString(),
        ]),
      ],
    ];
    $form['sync']['sync_submit'] = [
      '#title' => $this
        ->t('Run developer sync'),
      '#type' => 'link',
      '#url' => $this
        ->buildUrl('apigee_edge.developer_sync.run'),
      '#attributes' => [
        'class' => [
          'button',
          'button--primary',
        ],
      ],
    ];
    $form['sync']['background_sync_submit'] = [
      '#title' => $this
        ->t('Background developer sync'),
      '#type' => 'link',
      '#url' => $this
        ->buildUrl('apigee_edge.developer_sync.schedule'),
      '#attributes' => [
        'class' => [
          'button',
        ],
      ],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * Build URL for developer-user sync processes, using CSRF protection.
   *
   * @param string $route_name
   *   The name of the route.
   *
   * @return \Drupal\Core\Url
   *   The URL to redirect to.
   */
  protected function buildUrl(string $route_name) : Url {
    $url = Url::fromRoute($route_name);
    $token = \Drupal::csrfToken()
      ->get($url
      ->getInternalPath());
    $url
      ->setOptions([
      'query' => [
        'destination' => 'admin/config/apigee-edge/developer-settings/sync',
        'token' => $token,
      ],
    ]);
    return $url;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DeveloperSyncForm::$sdkConnector protected property The SDK connector service.
DeveloperSyncForm::buildForm public function Form constructor. Overrides FormInterface::buildForm
DeveloperSyncForm::buildUrl protected function Build URL for developer-user sync processes, using CSRF protection.
DeveloperSyncForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
DeveloperSyncForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
DeveloperSyncForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
DeveloperSyncForm::__construct public function Constructs a new DeveloperSyncForm.
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.