class AdsenseMainSettings in Google AdSense integration 8
Form for the adsense module general 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\adsense\Form\AdsenseMainSettings
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of AdsenseMainSettings
1 string reference to 'AdsenseMainSettings'
File
- src/
Form/ AdsenseMainSettings.php, line 16
Namespace
Drupal\adsense\FormView source
class AdsenseMainSettings extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'adsense_main_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'adsense.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
module_load_include('inc', 'adsense', 'help/adsense.help');
module_load_include('inc', 'adsense', 'includes/adsense.search_options');
$config = $this
->config('adsense.settings');
$form['help'] = [
'#type' => 'details',
'#open' => FALSE,
'#title' => $this
->t('Help and instructions'),
];
$form['help']['help'] = [
'#markup' => adsense_help_text(),
];
$form['adsense_basic_id'] = [
'#type' => 'textfield',
'#title' => $this
->t('Site Google AdSense Publisher ID'),
'#required' => TRUE,
'#default_value' => $config
->get('adsense_basic_id'),
'#pattern' => 'pub-[0-9]+',
'#description' => $this
->t('This is the Google AdSense Publisher ID for the site owner. It is used if no other ID is suitable. Get this in your Google Adsense account. It should be similar to %id.', [
'%id' => 'pub-9999999999999',
]),
];
$options = $this
->adsenseIdSettingsClientIdMods();
if (count($options) > 1) {
$form['adsense_id_module'] = [
'#type' => 'radios',
'#title' => $this
->t('Publisher ID module'),
'#default_value' => $config
->get('adsense_id_module'),
'#options' => $options,
];
}
else {
$form['adsense_id_module'] = [
'#type' => 'hidden',
'#value' => 'adsense_basic',
];
}
$form['adsense_unblock_ads'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display anti ad-block request?'),
'#default_value' => $config
->get('adsense_unblock_ads'),
'#description' => $this
->t("EXPERIMENTAL! Enabling this feature will add a mechanism that tries to detect when adblocker software is in use, displaying a polite request to the user to enable ads on this site. [@moreinfo]", [
'@moreinfo' => Link::fromTextAndUrl($this
->t('More information'), Url::fromUri('https://easylist.to/2013/05/10/anti-adblock-guide-for-site-admins.html'))
->toString(),
]),
];
$form['adsense_test_mode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable test mode?'),
'#default_value' => $config
->get('adsense_test_mode'),
'#description' => $this
->t('This enables you to test the AdSense module settings. This can be useful in some situations: for example, testing whether revenue sharing is working properly or not without having to display real ads on your site. It is best to test this after you log out.'),
];
$form['adsense_disable'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Disable Google AdSense ads?'),
'#default_value' => $config
->get('adsense_disable'),
'#description' => $this
->t('This disables all display of Google AdSense ads from your web site. This is useful in certain situations, such as site upgrades, or if you make a copy of the site for development and test purposes.'),
];
$form['adsense_placeholder'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Placeholder when ads are disabled?'),
'#default_value' => $config
->get('adsense_placeholder'),
'#description' => $this
->t('This causes an empty box to be displayed in place of the ads when they are disabled.'),
];
$form['adsense_placeholder_text'] = [
'#type' => 'textarea',
'#title' => $this
->t('Placeholder text to display'),
'#default_value' => $config
->get('adsense_placeholder_text'),
'#rows' => 3,
'#description' => $this
->t('Enter any text to display as a placeholder when ads are disabled.'),
];
$form['secret'] = [
'#type' => 'details',
'#open' => FALSE,
'#title' => $this
->t('Undocumented options'),
'#description' => $this
->t("Warning: Use of these options is AT YOUR OWN RISK. Google will never generate an ad with any of these options, so using one of them is a violation of Google AdSense's Terms and Conditions. USE OF THESE OPTIONS MAY RESULT IN GETTING BANNED FROM THE PROGRAM. You may lose all the revenue accumulated in your account. FULL RESPONSIBILITY FOR THE USE OF THESE OPTIONS IS YOURS. In other words, don't complain to the authors about getting banned, even if using one of these options was provided as a solution to a reported problem."),
];
$form['secret']['agreed'] = [
'#type' => 'details',
'#open' => FALSE,
'#title' => $this
->t('I agree'),
];
$form['secret']['agreed']['adsense_secret_language'] = [
'#type' => 'select',
'#title' => $this
->t('Language to display ads'),
'#default_value' => $config
->get('adsense_secret_language'),
'#options' => array_merge([
'' => 'Set by Google',
], AdsenseAdBase::adsenseLanguages()),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->configFactory()
->getEditable('adsense.settings');
$form_state
->cleanValues();
foreach ($form_state
->getValues() as $key => $value) {
$config
->set($key, Html::escape($value));
}
$config
->save();
parent::submitForm($form, $form_state);
}
/**
* Search for the available Publisher ID modules.
*
* @return array
* array of selectable Publisher ID functions
*/
private function adsenseIdSettingsClientIdMods() {
// @todo ModuleHandler::getImplementations.
$ret['adsense_basic'] = 'Always use the site Publisher ID.';
$funcs = get_defined_functions();
foreach ($funcs['user'] as $func) {
if (preg_match('!_adsense$!', $func)) {
$settings = $func('settings');
$ret[$func] = $settings['name'];
if (!empty($settings['desc'])) {
$ret[$func] .= "<div style='margin-left: 2.5em;' class='description'>{$settings['desc']}</div>";
}
}
}
return $ret;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AdsenseMainSettings:: |
private | function | Search for the available Publisher ID modules. | |
AdsenseMainSettings:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
AdsenseMainSettings:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
AdsenseMainSettings:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
AdsenseMainSettings:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
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. | |
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. |