class SpiChangeForm in Acquia Connector 8
Same name and namespace in other branches
- 8.2 src/Form/SpiChangeForm.php \Drupal\acquia_connector\Form\SpiChangeForm
- 3.x src/Form/SpiChangeForm.php \Drupal\acquia_connector\Form\SpiChangeForm
Change SPI Data form.
@package Drupal\acquia_connector\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\acquia_connector\Form\SpiChangeForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SpiChangeForm
1 string reference to 'SpiChangeForm'
File
- src/
Form/ SpiChangeForm.php, line 16
Namespace
Drupal\acquia_connector\FormView source
class SpiChangeForm extends ConfigFormBase {
/**
* The state service.
*
* @var \Drupal\Core\State\State
*/
protected $state;
/**
* Constructs a \Drupal\acquia_connector\Form object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\State\State $state
* The State handler.
*/
public function __construct(ConfigFactoryInterface $config_factory, State $state) {
parent::__construct($config_factory);
$this->state = $state;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('state'));
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'acquia_connector.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'acquia_connector_spi_change_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('acquia_connector.settings');
$blocked = $config
->get('spi.blocked');
$acquia_hosted = \Drupal::service('acquia_connector.spi')
->checkAcquiaHosted();
$environment_change = \Drupal::service('acquia_connector.spi')
->checkEnvironmentChange();
if (!$environment_change && !$blocked) {
$form['#markup'] = $this
->t("<h2>No changes detected</h2><p>This form is used to address changes in your site's environment. No changes are currently detected.</p>");
return $form;
}
elseif ($blocked) {
$form['env_change_action'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('The Acquia Connector is disabled and is not sending site profile data to Acquia Cloud for evaluation.'),
'#options' => [
'unblock' => $this
->t('Enable this site and send data to Acquia Cloud.'),
],
'#required' => TRUE,
];
}
else {
$env_changes = $config
->get('spi.environment_changes');
$off_acquia_hosting = array_key_exists('acquia_hosted', $env_changes) && !$acquia_hosted;
$form['env'] = [
'#type' => 'fieldset',
'#title' => $this
->t('<strong>The following changes have been detected in your site environment:</strong>'),
'#description' => [
'#theme' => 'item_list',
'#items' => $env_changes,
],
];
$form['env_change_action'] = [
'#type' => 'radios',
'#title' => $this
->t('How would you like to proceed?'),
'#options' => [
'block' => $this
->t('Disable this site from sending profile data to Acquia Cloud.'),
'update' => $this
->t('Update existing site with these changes.'),
'create' => $this
->t('Track this as a new site on Acquia Cloud.'),
],
'#required' => TRUE,
'#default_value' => $config
->get('spi.environment_changed_action'),
];
$form['identification'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Site Identification'),
'#collapsible' => FALSE,
'#states' => [
'visible' => [
':input[name="env_change_action"]' => [
'value' => 'create',
],
],
],
];
$form['identification']['site'] = [
'#prefix' => '<div class="acquia-identification">',
'#suffix' => '</div>',
'#weight' => -2,
];
$form['identification']['site']['name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Name'),
'#maxlength' => 255,
'#required' => TRUE,
'#default_value' => $this->state
->get('spi.site_name'),
];
$form['identification']['site']['machine_name'] = [
'#type' => 'machine_name',
'#title' => $this
->t('Machine name'),
'#maxlength' => 255,
'#required' => TRUE,
'#machine_name' => [
'exists' => [
$this,
'exists',
],
'source' => [
'identification',
'site',
'name',
],
],
'#default_value' => $this->state
->get('spi.site_machine_name'),
];
if ($acquia_hosted) {
$form['identification']['site']['name']['#disabled'] = TRUE;
$form['identification']['site']['machine_name']['#disabled'] = TRUE;
$form['identification']['site']['machine_name']['#default_value'] = \Drupal::service('acquia_connector.spi')
->getAcquiaHostedMachineName();
}
elseif ($off_acquia_hosting) {
unset($form['env_change_action']['#options']['block']);
unset($form['env_change_action']['#options']['update']);
unset($form['env_change_action']['#states']);
unset($form['identification']['site']['name']['#default_value']);
unset($form['identification']['site']['machine_name']['#default_value']);
$form['env_change_action']['#default_value'] = 'create';
$form['env_change_action']['#access'] = FALSE;
}
}
return parent::buildForm($form, $form_state);
}
/**
* Determines if the machine name already exists.
*
* @return bool
* FALSE.
*/
public function exists() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$config = $this
->configFactory()
->getEditable('acquia_connector.settings');
if (isset($values['env_change_action']['unblock']) && $values['env_change_action']['unblock'] == 'unblock') {
$config
->set('spi.environment_changed_action', $values['env_change_action']['unblock'])
->save();
}
else {
$config
->set('spi.environment_changed_action', $values['env_change_action'])
->save();
}
if ($values['env_change_action'] == 'create') {
$this->state
->set('spi.site_name', $values['name']);
$this->state
->set('spi.site_machine_name', $values['machine_name']);
}
parent::submitForm($form, $form_state);
// Send information as soon as the key/identifier pair is submitted.
$response = \Drupal::service('acquia_connector.spi')
->sendFullSpi(ACQUIA_CONNECTOR_ACQUIA_SPI_METHOD_CREDS);
\Drupal::service('acquia_connector.spi')
->spiProcessMessages($response);
$form_state
->setRedirect('system.status');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
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 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
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. | |
SpiChangeForm:: |
protected | property | The state service. | |
SpiChangeForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SpiChangeForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SpiChangeForm:: |
public | function | Determines if the machine name already exists. | |
SpiChangeForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SpiChangeForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SpiChangeForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SpiChangeForm:: |
public | function |
Constructs a \Drupal\acquia_connector\Form object. Overrides ConfigFormBase:: |
|
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. |