class GoogleAdwordsAdminSettings in Google AdWords Conversion Tracking 8
Class GoogleAdwordsAdminSettings.
@package Drupal\google_adwords\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\google_adwords\Form\GoogleAdwordsAdminSettings
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of GoogleAdwordsAdminSettings
1 string reference to 'GoogleAdwordsAdminSettings'
File
- src/
Form/ GoogleAdwordsAdminSettings.php, line 21 - Contains \Drupal\google_adwords\Form\GoogleAdwordsAdminSettings.
Namespace
Drupal\google_adwords\FormView source
class GoogleAdwordsAdminSettings extends ConfigFormBase {
/**
* \Drupal\Core\Entity\EntityTypeManager definition.
*
* @var \Drupal\Core\Entity\EntityTypeManager
*/
protected $entity_type_manager;
/**
* GoogleAdwordsAdminSettings constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManager $entity_type_manager) {
parent::__construct($config_factory);
$this->entity_type_manager = $entity_type_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'google_adwords.adminsettings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'google_adwords_admin_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('google_adwords.adminsettings');
$form['conversion'] = array(
'#type' => 'fieldset',
'#title' => t('Default Conversion settings'),
'#collapsible' => FALSE,
);
$form['conversion']['conversion_id'] = array(
'#type' => 'textfield',
'#title' => t('Conversion ID'),
'#default_value' => $config
->get('conversion_id'),
'#size' => 15,
'#maxlength' => 255,
'#required' => FALSE,
'#description' => '',
);
$form['conversion']['language'] = array(
'#type' => 'textfield',
'#title' => t('Conversion Language'),
'#default_value' => $config
->get('language'),
'#size' => 15,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => '',
);
$form['conversion']['format'] = array(
'#type' => 'textfield',
'#title' => t('Conversion Format'),
'#default_value' => $config
->get('format'),
'#size' => 15,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => '',
);
$form['conversion']['color'] = array(
'#type' => 'textfield',
'#title' => t('Conversion Color'),
'#default_value' => $config
->get('color'),
'#size' => 15,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => '',
);
$form['conversion']['external_script'] = array(
'#type' => 'textfield',
'#title' => t('External JavaScript'),
'#default_value' => $config
->get('external_script'),
'#size' => 80,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => '',
);
// Render the role overview.
$form['conversion']['roles'] = array(
'#type' => 'fieldset',
'#title' => t('User Role Tracking'),
'#collapsible' => TRUE,
'#description' => t('Define what user roles should be tracked.'),
);
/**
* @var \Drupal\user\RoleStorage $role_storage
* Storage object for role entities
*/
$role_storage = $this->entity_type_manager
->getStorage('user_role');
/**
* @var int|array[/Drupal/Core/Entity] $roles
*/
$roles = $role_storage
->getQuery()
->execute();
if (is_array($roles)) {
foreach ($role_storage
->loadMultiple($roles) as $role) {
/**
* @var \Drupal\user\Entity\Role $role
* each role entity
*/
/**
* @var string $var_name
* admin settings config var name for the role
*
* @note that role ids are no longer numeric ids in a table
* so their ids should be safe to use in keys
*/
$var_name = 'google_adwords_track_' . $role
->id();
$form['conversion']['roles'][$var_name] = array(
'#type' => 'checkbox',
'#title' => $role
->label(),
// this should already be translated
'#default_value' => $config
->get($var_name),
);
}
}
else {
$form['conversion']['roles']['none'] = array(
'#type' => 'markup',
'#markup' => $this
->t('No roles found in the system. None can be marked for conversion'),
'#prefix' => '<strong>',
'#suffix' => '</strong>',
);
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('google_adwords.adminsettings')
->save();
}
}
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. | |
GoogleAdwordsAdminSettings:: |
protected | property | \Drupal\Core\Entity\EntityTypeManager definition. | |
GoogleAdwordsAdminSettings:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
GoogleAdwordsAdminSettings:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
GoogleAdwordsAdminSettings:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
GoogleAdwordsAdminSettings:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
GoogleAdwordsAdminSettings:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
GoogleAdwordsAdminSettings:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
GoogleAdwordsAdminSettings:: |
public | function |
GoogleAdwordsAdminSettings constructor. Overrides ConfigFormBase:: |
|
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. |