You are here

class CustomSearchV2Ad in Google AdSense integration 8

Provides an AdSense custom search engine form.

Plugin annotation


@AdsenseAd(
  id = "csev2",
  name = @Translation("CSE V2 Search"),
  isSearch = TRUE,
  needsSlot = TRUE,
  version = 2
)

Hierarchy

Expanded class hierarchy of CustomSearchV2Ad

1 file declares its use of CustomSearchV2Ad
CustomSearchAdBlock.php in src/Plugin/Block/CustomSearchAdBlock.php

File

src/Plugin/AdsenseAd/CustomSearchV2Ad.php, line 19

Namespace

Drupal\adsense\Plugin\AdsenseAd
View source
class CustomSearchV2Ad extends SearchAdBase {

  /**
   * Ad slot ID.
   *
   * @var string
   */
  private $slot;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id = '', $plugin_definition = NULL, $config_factory = NULL, $module_handler = NULL, $current_user = NULL) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $config_factory, $module_handler, $current_user);
    $this->slot = !empty($configuration['slot']) ? $configuration['slot'] : '';
  }

  /**
   * {@inheritdoc}
   */
  public function getAdPlaceholder() {
    if (!empty($this->slot)) {
      $client = PublisherId::get();
      $content = "CSE v2\ncx = partner-{$client}:{$this->slot}";
      return [
        '#content' => [
          '#markup' => nl2br($content),
        ],
        '#format' => 'Search Box v2',
      ];
    }
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getAdContent() {
    if (!empty($this->slot)) {
      $client = PublisherId::get();
      $this->moduleHandler
        ->alter('adsense', $client);
      return [
        '#theme' => 'adsense_cse_v2_searchbox',
        '#client' => $client,
        '#slot' => $this->slot,
      ];
    }
    return [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdsenseAdBase::$configFactory protected property Config factory.
AdsenseAdBase::$currentUser protected property Current user.
AdsenseAdBase::$moduleHandler protected property Module handler.
AdsenseAdBase::adsenseLanguages public static function List of available languages. Overrides AdsenseAdInterface::adsenseLanguages
AdsenseAdBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
AdsenseAdBase::createAd public static function Creates the ad object, as specified by the definitions in the parameter. Overrides AdsenseAdInterface::createAd
AdsenseAdBase::display public function Display ad HTML.
AdsenseAdBase::isDisabled public static function Check if ads display is disabled.
CustomSearchV2Ad::$slot private property Ad slot ID.
CustomSearchV2Ad::getAdContent public function Return the ad content. Overrides AdsenseAdInterface::getAdContent
CustomSearchV2Ad::getAdPlaceholder public function Return the ad placeholder. Overrides AdsenseAdInterface::getAdPlaceholder
CustomSearchV2Ad::__construct public function Creates a new AdsenseAdBase instance. Overrides AdsenseAdBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SearchAdBase::adsenseAdFormats public static function This is the array that holds all ad formats. Overrides AdsenseAdInterface::adsenseAdFormats
SearchAdBase::adsenseCountries public static function Supply available countries for the search configuration forms.
SearchAdBase::adsenseEncodings public static function Supply available encodings for the search configuration forms.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.