You are here

class GoogleAdwordsAdminSettings in Google AdWords Conversion Tracking 8

Class GoogleAdwordsAdminSettings.

@package Drupal\google_adwords\Form

Hierarchy

Expanded class hierarchy of GoogleAdwordsAdminSettings

1 string reference to 'GoogleAdwordsAdminSettings'
google_adwords.routing.yml in ./google_adwords.routing.yml
google_adwords.routing.yml

File

src/Form/GoogleAdwordsAdminSettings.php, line 21
Contains \Drupal\google_adwords\Form\GoogleAdwordsAdminSettings.

Namespace

Drupal\google_adwords\Form
View 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

Namesort descending Modifiers Type Description Overrides
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
GoogleAdwordsAdminSettings::$entity_type_manager protected property \Drupal\Core\Entity\EntityTypeManager definition.
GoogleAdwordsAdminSettings::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
GoogleAdwordsAdminSettings::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
GoogleAdwordsAdminSettings::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
GoogleAdwordsAdminSettings::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
GoogleAdwordsAdminSettings::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
GoogleAdwordsAdminSettings::validateForm public function Form validation handler. Overrides FormBase::validateForm
GoogleAdwordsAdminSettings::__construct public function GoogleAdwordsAdminSettings constructor. Overrides ConfigFormBase::__construct
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
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.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.