class DeveloperSyncForm in Apigee Edge 8
Provides a form to start developer synchronization.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\apigee_edge\Form\DeveloperSyncForm
Expanded class hierarchy of DeveloperSyncForm
1 string reference to 'DeveloperSyncForm'
File
- src/
Form/ DeveloperSyncForm.php, line 31
Namespace
Drupal\apigee_edge\FormView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DeveloperSyncForm:: |
protected | property | The SDK connector service. | |
DeveloperSyncForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
DeveloperSyncForm:: |
protected | function | Build URL for developer-user sync processes, using CSRF protection. | |
DeveloperSyncForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
DeveloperSyncForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
DeveloperSyncForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
DeveloperSyncForm:: |
public | function | Constructs a new DeveloperSyncForm. | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |