class AdminSettings in Doubleclick for Publishers (DFP) 8
Defines a form that configures DFP global settings.
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\dfp\Form\AdminSettings uses TargetingFormTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of AdminSettings
1 string reference to 'AdminSettings'
File
- src/
Form/ AdminSettings.php, line 21 - Contains \Drupal\dfp\Form\AdminSettings.
Namespace
Drupal\dfp\FormView source
class AdminSettings extends ConfigFormBase {
use TargetingFormTrait;
/**
* Entity bundle information.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $bundleInfo;
/**
* Constructs a \Drupal\dfp\Form\AdminSettings object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeBundleInfoInterface $bundle_info) {
parent::__construct($config_factory);
$this->bundleInfo = $bundle_info;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity_type.bundle.info'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'dfp_admin_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'dfp.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$config = $this
->config('dfp.settings');
// @todo vertical tabs?
// Default tag settings.
$form['global_tag_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Global Tag Settings'),
'#open' => TRUE,
];
$form['global_tag_settings']['network_id'] = [
'#type' => 'textfield',
'#title' => $this
->t('Network ID'),
'#default_value' => $config
->get('network_id'),
'#required' => TRUE,
'#description' => $this
->t('The Network ID to use on all tags. According to Google this value should begin with a /.'),
];
$form['global_tag_settings']['adunit_pattern'] = [
'#type' => 'textfield',
'#title' => $this
->t('Default Ad Unit Pattern'),
'#required' => FALSE,
'#maxlength' => 255,
'#default_value' => $config
->get('adunit_pattern'),
'#description' => $this
->t('Use the tokens below to define how the default ad unit should display. This can be overridden on each tag. The network id will be included automatically. Example: [current-page:url:args:value:0]/[current-page:url:args:value:1]/[dfp_tag:slot]'),
];
$form['global_tag_settings']['click_url'] = [
'#type' => 'textfield',
'#title' => $this
->t('DFP Click URL (Sync mode only)'),
'#default_value' => $config
->get('click_url'),
'#description' => $this
->t('Sets a click URL on each DFP tag. Useful for intercepting ad click calls for reporting. Values beginning with http:// are treated as absolute; otherwise relative to current site domain.'),
'#states' => [
'enabled' => [
'input[name="async_rendering"]' => [
'checked' => FALSE,
],
],
],
];
// @todo: Add back token browser.
$form['global_tag_settings']['async_rendering'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Render ads asynchronously'),
'#default_value' => $config
->get('async_rendering'),
'#description' => $this
->t('This can speed up page rendering time by loading page content without waiting for ads to load.'),
];
$form['global_tag_settings']['disable_init_load'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Disable initial ad load'),
'#default_value' => $config
->get('disable_init_load'),
'#description' => $this
->t('(Async mode only) Disables the initial fetch of ads from Google when the page is first loaded. Calls to refresh() can still be used to fetch ads.'),
'#states' => [
'enabled' => [
'input[name="async_rendering"]' => [
'checked' => TRUE,
],
],
],
];
$form['global_tag_settings']['single_request'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Combine all ad requests into a single request'),
'#default_value' => $config
->get('single_request'),
'#description' => $this
->t('This can speed up page rendering time by limiting the number of external requests.'),
];
// Global display options.
$form['global_display_options'] = [
'#type' => 'details',
'#title' => $this
->t('Global Display Options'),
'#open' => TRUE,
];
$form['global_display_options']['default_slug'] = [
'#type' => 'textfield',
'#title' => $this
->t('Global Slug'),
'#default_value' => $config
->get('default_slug'),
'#required' => FALSE,
'#description' => $this
->t('Slug all ad tags with this label. Example: Advertisement'),
];
$form['global_display_options']['collapse_empty_divs'] = [
'#type' => 'radios',
'#title' => $this
->t('Collapse empty divs'),
'#default_value' => $config
->get('collapse_empty_divs'),
'#options' => [
0 => $this
->t('Never'),
1 => $this
->t('Collapse only if no ad is served'),
2 => $this
->t('Expand only if an ad is served'),
],
'#description' => $this
->t('<dl><dt>Never</dt><dd>Never collapse ad slots.</dd><dt>Collapse only</dt><dd>Collapse before any ad is loaded. Useful if ad slots will get filled most of the time.</dd><dt>Expand only</dt><dd>Collapse all divs on the page before any ads are fetched and expand if an ad is loaded into the ad slot. Useful if ad slots will stay empty most of the time.</dd></dl>'),
];
$form['global_display_options']['hide_slug'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Hide slug if no ad is served (recommended)'),
'#default_value' => $config
->get('hide_slug'),
'#states' => [
'visible' => [
'input[name="collapse_empty_divs"]' => [
'!value' => 0,
],
],
],
];
// Global targeting options.
$form['targeting_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Global Targeting'),
'#open' => TRUE,
];
$existing_targeting = $this
->getExistingTargeting($form_state, $config
->get('targeting'));
$this
->addTargetingForm($form['targeting_settings'], $existing_targeting);
// AdTest Settings.
$form['adtest'] = [
'#type' => 'details',
'#title' => $this
->t('Ad Test Settings'),
'#open' => TRUE,
];
$form['adtest']['adtest_adunit_pattern'] = [
'#type' => 'textfield',
'#title' => $this
->t('Ad Unit Pattern for Ad Tests'),
'#description' => $this
->t('Override the Ad Unit value for all the ad tags on a page by adding ?adtest=true to the URL. Use the tokens below to define how the ad unit should display. Example: [dfp_tag:network_id]/test/[dfp_tag:slot]'),
'#default_value' => $config
->get('adtest_adunit_pattern'),
];
// @todo Add back token browser.
// @todo Drupal 7 also had the ability to inject Javascript. Discuss whether
// or not this should be implemented.
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getValue('click_url') && $form_state
->getValue('async_rendering')) {
$form_state
->setErrorByName('click_url', $this
->t('Setting a click URL does not work with async rendering.'));
}
if (preg_match(TagInterface::ADUNIT_PATTERN_VALIDATION_REGEX, $form_state
->getValue('adunit_pattern'))) {
$form_state
->setErrorByName('adunit_pattern', $this
->t('Ad Unit Patterns can only include letters, numbers, hyphens, dashes, periods, slashes and tokens.'));
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
if (!$values['async_rendering']) {
$values['disable_init_load'] = FALSE;
}
$this
->config('dfp.settings')
->set('network_id', $values['network_id'])
->set('adunit_pattern', $values['adunit_pattern'])
->set('click_url', $values['click_url'])
->set('async_rendering', $values['async_rendering'])
->set('disable_init_load', $values['disable_init_load'])
->set('single_request', $values['single_request'])
->set('default_slug', $values['default_slug'])
->set('collapse_empty_divs', $values['collapse_empty_divs'])
->set('adtest_adunit_pattern', $values['adtest_adunit_pattern'])
->set('targeting', $values['targeting'])
->set('hide_slug', $values['hide_slug'])
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AdminSettings:: |
protected | property | Entity bundle information. | |
AdminSettings:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
AdminSettings:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
AdminSettings:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
AdminSettings:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
AdminSettings:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
AdminSettings:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
AdminSettings:: |
public | function |
Constructs a \Drupal\dfp\Form\AdminSettings object. Overrides ConfigFormBase:: |
|
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. | |
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. | |
TargetingFormTrait:: |
protected | function | Helper form builder for an individual target. | |
TargetingFormTrait:: |
protected | function | Helper form builder for the targeting form. | |
TargetingFormTrait:: |
protected | function | Returns the current targets. | |
TargetingFormTrait:: |
public | function | Ajax callback for adding targets to the targeting form. | |
TargetingFormTrait:: |
public static | function | Validation function used by an individual target in the targeting form. | |
TargetingFormTrait:: |
public | function | Submit handler to add more targets to an ad tag. | |
TargetingFormTrait:: |
public static | function | Validation function used by the targeting form. | |
TargetingFormTrait:: |
protected static | function | Helper function that removes empty targets form form values. | |
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. |