class SettingsForm in Salesforce Suite 8.3
Same name in this branch
- 8.3 src/Form/SettingsForm.php \Drupal\salesforce\Form\SettingsForm
- 8.3 modules/salesforce_logger/src/Form/SettingsForm.php \Drupal\salesforce_logger\Form\SettingsForm
- 8.3 modules/salesforce_encrypt/src/Form/SettingsForm.php \Drupal\salesforce_encrypt\Form\SettingsForm
Same name and namespace in other branches
- 8.4 src/Form/SettingsForm.php \Drupal\salesforce\Form\SettingsForm
- 5.0.x src/Form/SettingsForm.php \Drupal\salesforce\Form\SettingsForm
Creates authorization form for Salesforce.
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\salesforce\Form\SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsForm
1 string reference to 'SettingsForm'
File
- src/
Form/ SettingsForm.php, line 16
Namespace
Drupal\salesforce\FormView source
class SettingsForm extends ConfigFormBase {
/**
* The Salesforce REST client.
*
* @var \Drupal\salesforce\Rest\RestClientInterface
*/
protected $client;
/**
* The sevent dispatcher service..
*
* @var \Drupal\Core\State\StateInterface
*/
protected $eventDispatcher;
/**
* Constructs a \Drupal\system\ConfigFormBase object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\salesforce\Rest\RestClientInterface $salesforce_client
* The factory for configuration objects.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher.
*/
public function __construct(ConfigFactoryInterface $config_factory, RestClientInterface $salesforce_client, EventDispatcherInterface $event_dispatcher) {
parent::__construct($config_factory);
$this->client = $salesforce_client;
$this->eventDispatcher = $event_dispatcher;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('salesforce.client'), $container
->get('event_dispatcher'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'salesforce_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'salesforce.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// We're not actually doing anything with this, but may figure out
// something that makes sense.
$config = $this
->config('salesforce.settings');
$definition = \Drupal::service('config.typed')
->getDefinition('salesforce.settings');
$definition = $definition['mapping'];
$form['endpoint_verification'] = [
'#title' => $this
->t($definition['endpoint_verification']['label']),
'#type' => 'checkbox',
'#description' => $this
->t($definition['endpoint_verification']['description']),
'#default_value' => $config
->get('endpoint_verification'),
];
$form['use_latest'] = [
'#title' => $this
->t($definition['use_latest']['label']),
'#type' => 'checkbox',
'#description' => $this
->t($definition['use_latest']['description']),
'#default_value' => $config
->get('use_latest'),
];
$versions = [];
try {
$versions = $this
->getVersionOptions();
} catch (\Exception $e) {
$href = new Url('salesforce.authorize');
drupal_set_message($this
->t('Error when connecting to Salesforce. Please <a href="@href">check your credentials</a> and try again: %message', [
'@href' => $href
->toString(),
'%message' => $e
->getMessage(),
]), 'error');
}
$form['rest_api_version'] = [
'#title' => $this
->t($definition['rest_api_version']['label']),
'#description' => $this
->t($definition['rest_api_version']['description']),
'#type' => 'select',
'#options' => $versions,
'#tree' => TRUE,
'#default_value' => $config
->get('rest_api_version')['version'],
'#states' => [
'visible' => [
':input[name="use_latest"]' => [
'checked' => FALSE,
],
],
],
];
if (\Drupal::moduleHandler()
->moduleExists('salesforce_push')) {
$form['global_push_limit'] = [
'#title' => $this
->t($definition['global_push_limit']['label']),
'#type' => 'number',
'#description' => $this
->t($definition['global_push_limit']['description']),
'#required' => TRUE,
'#default_value' => $config
->get('global_push_limit'),
'#min' => 0,
];
}
if (\Drupal::moduleHandler()
->moduleExists('salesforce_pull')) {
$form['pull_max_queue_size'] = [
'#title' => $this
->t($definition['pull_max_queue_size']['label']),
'#type' => 'number',
'#description' => $this
->t($definition['pull_max_queue_size']['description']),
'#required' => TRUE,
'#default_value' => $config
->get('pull_max_queue_size'),
'#min' => 0,
];
}
if (\Drupal::moduleHandler()
->moduleExists('salesforce_mapping')) {
$form['limit_mapped_object_revisions'] = [
'#title' => $this
->t($definition['limit_mapped_object_revisions']['label']),
'#description' => $this
->t($definition['limit_mapped_object_revisions']['description']),
'#type' => 'number',
'#required' => TRUE,
'#default_value' => $config
->get('limit_mapped_object_revisions'),
'#min' => 0,
];
$form['show_all_objects'] = [
'#title' => $this
->t($definition['show_all_objects']['label']),
'#description' => $this
->t($definition['show_all_objects']['description']),
'#type' => 'checkbox',
'#default_value' => $config
->get('show_all_objects'),
];
}
if (\Drupal::moduleHandler()
->moduleExists('salesforce_push') || \Drupal::moduleHandler()
->moduleExists('salesforce_pull')) {
$form['standalone'] = [
'#title' => $this
->t($definition['standalone']['label']),
'#description' => $this
->t($definition['standalone']['description']),
'#type' => 'checkbox',
'#default_value' => $config
->get('standalone'),
];
if (\Drupal::moduleHandler()
->moduleExists('salesforce_push')) {
$standalone_push_url = Url::fromRoute('salesforce_push.endpoint', [
'key' => \Drupal::state()
->get('system.cron_key'),
], [
'absolute' => TRUE,
]);
$form['standalone_push_url'] = [
'#type' => 'item',
'#title' => $this
->t('Standalone Push URL'),
'#markup' => $this
->t('<a href="@url">@url</a>', [
'@url' => $standalone_push_url
->toString(),
]),
'#states' => [
'visible' => [
':input#edit-standalone' => [
'checked' => TRUE,
],
],
],
];
}
if (\Drupal::moduleHandler()
->moduleExists('salesforce_pull')) {
$standalone_pull_url = Url::fromRoute('salesforce_pull.endpoint', [
'key' => \Drupal::state()
->get('system.cron_key'),
], [
'absolute' => TRUE,
]);
$form['standalone_pull_url'] = [
'#type' => 'item',
'#title' => $this
->t('Standalone Pull URL'),
'#markup' => $this
->t('<a href="@url">@url</a>', [
'@url' => $standalone_pull_url
->toString(),
]),
'#states' => [
'visible' => [
':input#edit-standalone' => [
'checked' => TRUE,
],
],
],
];
}
}
$form = parent::buildForm($form, $form_state);
$form['creds']['actions'] = $form['actions'];
unset($form['actions']);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('salesforce.settings');
$config
->set('show_all_objects', $form_state
->getValue('show_all_objects'));
$config
->set('standalone', $form_state
->getValue('standalone'));
$config
->set('global_push_limit', $form_state
->getValue('global_push_limit'));
$config
->set('pull_max_queue_size', $form_state
->getValue('pull_max_queue_size'));
$config
->set('limit_mapped_object_revisions', $form_state
->getValue('limit_mapped_object_revisions'));
$config
->set('endpoint_verification', $form_state
->getValue('endpoint_verification'));
$use_latest = $form_state
->getValue('use_latest');
$config
->set('use_latest', $use_latest);
if (!$use_latest) {
$versions = $this->client
->getVersions();
$version = $versions[$form_state
->getValue('rest_api_version')];
$config
->set('rest_api_version', $version);
}
$config
->save();
parent::submitForm($form, $form_state);
}
/**
* Helper method to generate Salesforce option list for select element.
*
* @return array
* The version options.
*/
protected function getVersionOptions() {
$versions = $this->client
->getVersions();
array_walk($versions, function (&$item, $key) {
$item = $item['label'];
});
return $versions;
}
}
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. | |
SettingsForm:: |
protected | property | The Salesforce REST client. | |
SettingsForm:: |
protected | property | The sevent dispatcher service.. | |
SettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SettingsForm:: |
protected | function | Helper method to generate Salesforce option list for select element. | |
SettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase 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. |