You are here

class EditTexts in TacJS 8.2

Same name and namespace in other branches
  1. 8.6 src/Form/Steps/EditTexts.php \Drupal\tacjs\Form\Steps\EditTexts
  2. 8.3 src/Form/Steps/EditTexts.php \Drupal\tacjs\Form\Steps\EditTexts
  3. 8.4 src/Form/Steps/EditTexts.php \Drupal\tacjs\Form\Steps\EditTexts
  4. 8.5 src/Form/Steps/EditTexts.php \Drupal\tacjs\Form\Steps\EditTexts

Class EditTexts.

@package Drupal\tacjs\Form

Hierarchy

Expanded class hierarchy of EditTexts

1 string reference to 'EditTexts'
tacjs.routing.yml in ./tacjs.routing.yml
tacjs.routing.yml

File

src/Form/Steps/EditTexts.php, line 14

Namespace

Drupal\tacjs\Form\Steps
View source
class EditTexts extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'tacjs_edit_texts';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = \Drupal::getContainer()
      ->get('config.factory')
      ->getEditable('tacjs.settings');
    $texts = [
      [
        'id' => 'adblock',
        'msg' => 'Hello! This site is transparent and lets you chose the 3rd party services you want to allow.',
      ],
      [
        'id' => 'adblock_call',
        'msg' => 'Please disable your adblocker to start customizing.',
      ],
      [
        'id' => 'reload',
        'msg' => 'Refresh the page',
      ],
      [
        'id' => 'alertBigScroll',
        'msg' => 'By continuing to scroll,',
      ],
      [
        'id' => 'alertBigClick',
        'msg' => 'If you continue to browse this website,',
      ],
      [
        'id' => 'alertBig',
        'msg' => 'you are allowing all third-party services',
      ],
      [
        'id' => 'alertBigPrivacy',
        'msg' => 'This site uses cookies and gives you control over what you want to activate',
      ],
      [
        'id' => 'alertSmall',
        'msg' => 'Manage services',
      ],
      [
        'id' => 'personalize',
        'msg' => 'Personalize',
      ],
      [
        'id' => 'acceptAll',
        'msg' => 'OK, accept all',
      ],
      [
        'id' => 'close',
        'msg' => 'Close',
      ],
      [
        'id' => 'privacyUrl',
        'msg' => 'Privacy policy',
      ],
      [
        'id' => 'all',
        'msg' => 'Preference for all services',
      ],
      [
        'id' => 'info',
        'msg' => 'Protecting your privacy',
      ],
      [
        'id' => 'disclaimer',
        'msg' => 'By allowing these third party services, you accept their cookies and the use of tracking technologies necessary for their proper functioning.',
      ],
      [
        'id' => 'allow',
        'msg' => 'Allow',
      ],
      [
        'id' => 'deny',
        'msg' => 'Deny',
      ],
      [
        'id' => 'noCookie',
        'msg' => 'This service does not use cookie.',
      ],
      [
        'id' => 'useCookie',
        'msg' => 'This service can install',
      ],
      [
        'id' => 'useCookieCurrent',
        'msg' => 'This service has installed',
      ],
      [
        'id' => 'useNoCookie',
        'msg' => 'This service has not installed any cookie.',
      ],
      [
        'id' => 'more',
        'msg' => 'Read more',
      ],
      [
        'id' => 'source',
        'msg' => 'View the official website',
      ],
      [
        'id' => 'credit',
        'msg' => 'Cookies manager by tarteaucitron.js',
      ],
      [
        'id' => 'toggleInfoBox',
        'msg' => 'Show/hide informations about cookie storage',
      ],
      [
        'id' => 'title',
        'msg' => 'Cookies management panel',
      ],
      [
        'id' => 'cookieDetail',
        'msg' => 'Cookie detail for',
      ],
      [
        'id' => 'ourSite',
        'msg' => 'on our site',
      ],
      [
        'id' => 'newWindow',
        'msg' => '(new window)',
      ],
      [
        'id' => 'allowAll',
        'msg' => 'Allow all cookies',
      ],
      [
        'id' => 'denyAll',
        'msg' => 'Deny all cookies',
      ],
      [
        'id' => 'fallback',
        'msg' => 'is disabled.',
      ],
      [
        'id' => 'ads_title',
        'msg' => 'Advertising network',
      ],
      [
        'id' => 'ads_details',
        'msg' => 'Ad networks can generate revenue by selling advertising space on the site.',
      ],
      [
        'id' => 'analytic_title',
        'msg' => 'Audience measurement',
      ],
      [
        'id' => 'analytic_details',
        'msg' => 'The audience measurement services used to generate useful statistics attendance to improve the site.',
      ],
      [
        'id' => 'social_title',
        'msg' => 'Social networks',
      ],
      [
        'id' => 'social_details',
        'msg' => 'Social networks can improve the usability of the site and help to promote it via the shares.',
      ],
      [
        'id' => 'video_title',
        'msg' => 'Videos',
      ],
      [
        'id' => 'video_details',
        'msg' => 'Video sharing services help to add rich media on the site and increase its visibility.',
      ],
      [
        'id' => 'comment_title',
        'msg' => 'Comments',
      ],
      [
        'id' => 'comment_details',
        'msg' => 'Comments managers facilitate the filing of comments and fight against spam.',
      ],
      [
        'id' => 'support_title',
        'msg' => 'Support',
      ],
      [
        'id' => 'support_details',
        'msg' => 'Support services allow you to get in touch with the site team and help to improve it.',
      ],
      [
        'id' => 'api_title',
        'msg' => 'APIs',
      ],
      [
        'id' => 'api_details',
        'msg' => 'APIs are used to load scripts, geolocation, search engines, translations, ...',
      ],
      [
        'id' => 'other_title',
        'msg' => 'Other',
      ],
      [
        'id' => 'other_details',
        'msg' => 'Services to display web content.',
      ],
    ];
    $form['texts'] = [
      '#prefix' => '<p>' . t('Enter the text that will be presented to your website users. The same text is used in both the cookie declaration and the consent dialog.') . '<br />' . t('Translate the text on the <a href=":translate">User interface translation</a> page.', [
        ':translate' => Url::fromRoute('locale.translate_page')
          ->toString(),
      ]) . '</p>',
      '#type' => 'table',
      '#header' => [
        'original' => $this
          ->t('Original'),
        'destination' => $this
          ->t('Destination'),
      ],
      '#rows' => [],
    ];
    for ($i = 0; $i < count($texts); $i++) {
      $form['texts'][$i] = [
        'original' => [
          '#type' => 'inline_template',
          '#template' => '<strong>{{ msg }}</strong>',
          '#context' => [
            'msg' => $texts[$i]['msg'],
          ],
        ],
        'destination' => [
          '#type' => 'textarea',
          '#title' => t('Destination'),
          '#title_display' => 'invisible',
          '#default_value' => $config
            ->get('texts.' . $texts[$i]['id']),
        ],
      ];
    }
    $form['submit'] = [
      '#type' => 'submit',
      '#value' => t('Save'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = \Drupal::getContainer()
      ->get('config.factory')
      ->getEditable('tacjs.settings');
    $texts = [
      'adblock',
      'adblock_call',
      'reload',
      'alertBigScroll',
      'alertBigClick',
      'alertBig',
      'alertBigPrivacy',
      'alertSmall',
      'personalize',
      'acceptAll',
      'close',
      'privacyUrl',
      'all',
      'info',
      'disclaimer',
      'allow',
      'deny',
      'noCookie',
      'useCookie',
      'useCookieCurrent',
      'useNoCookie',
      'more',
      'source',
      'credit',
      'toggleInfoBox',
      'title',
      'cookieDetail',
      'ourSite',
      'newWindow',
      'allowAll',
      'denyAll',
      'fallback',
      'ads_title',
      'ads_details',
      'analytic_title',
      'analytic_details',
      'social_title',
      'social_details',
      'video_title',
      'video_details',
      'comment_title',
      'comment_details',
      'support_title',
      'support_details',
      'api_title',
      'api_details',
      'other_title',
      'other_details',
    ];
    for ($i = 0; $i < count($texts); $i++) {
      $config
        ->set('texts.' . $texts[$i], $form_state
        ->getValue('texts')[$i]['destination']);
    }
    $config
      ->save();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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
EditTexts::buildForm public function Form constructor. Overrides FormInterface::buildForm
EditTexts::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
EditTexts::submitForm public function Form submission handler. Overrides FormInterface::submitForm
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create 87
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.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
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.