You are here

class LingotekSettingsTabUtilitiesForm in Lingotek Translation 3.5.x

Same name and namespace in other branches
  1. 8 src/Form/LingotekSettingsTabUtilitiesForm.php \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm
  2. 8.2 src/Form/LingotekSettingsTabUtilitiesForm.php \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm
  3. 4.0.x src/Form/LingotekSettingsTabUtilitiesForm.php \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm
  4. 3.0.x src/Form/LingotekSettingsTabUtilitiesForm.php \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm
  5. 3.1.x src/Form/LingotekSettingsTabUtilitiesForm.php \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm
  6. 3.2.x src/Form/LingotekSettingsTabUtilitiesForm.php \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm
  7. 3.3.x src/Form/LingotekSettingsTabUtilitiesForm.php \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm
  8. 3.4.x src/Form/LingotekSettingsTabUtilitiesForm.php \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm
  9. 3.6.x src/Form/LingotekSettingsTabUtilitiesForm.php \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm
  10. 3.7.x src/Form/LingotekSettingsTabUtilitiesForm.php \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm
  11. 3.8.x src/Form/LingotekSettingsTabUtilitiesForm.php \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm

Tab for running Lingotek utilities in the settings page.

Hierarchy

Expanded class hierarchy of LingotekSettingsTabUtilitiesForm

2 files declare their use of LingotekSettingsTabUtilitiesForm
LingotekSettingsController.php in src/Controller/LingotekSettingsController.php
LingotekSettingsTabUtilitiesFormTest.php in tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php

File

src/Form/LingotekSettingsTabUtilitiesForm.php, line 17

Namespace

Drupal\lingotek\Form
View source
class LingotekSettingsTabUtilitiesForm extends LingotekConfigFormBase {

  /**
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * The route builder service.
   *
   * @var \Drupal\Core\Routing\RouteBuilderInterface
   */
  protected $routeBuilder;

  /**
   * Constructs a \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm object.
   *
   * @param \Drupal\lingotek\LingotekInterface $lingotek
   *   The lingotek service.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config
   *   The factory for configuration objects.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state key/value store.
   * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
   *   The route builder service.
   * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
   *   The url generator.
   * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator
   *   The link generator.
   */
  public function __construct(LingotekInterface $lingotek, ConfigFactoryInterface $config, StateInterface $state, RouteBuilderInterface $route_builder, UrlGeneratorInterface $url_generator = NULL, LinkGeneratorInterface $link_generator = NULL) {
    parent::__construct($lingotek, $config, $url_generator, $link_generator);
    $this->state = $state;
    $this->routeBuilder = $route_builder;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('lingotek'), $container
      ->get('config.factory'), $container
      ->get('state'), $container
      ->get('router.builder'), $container
      ->get('url_generator'), $container
      ->get('link_generator'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFormID() {
    return 'lingotek.settings_tab_utilities_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['utilities'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Utilities'),
    ];
    $lingotek_table = [
      '#type' => 'table',
      '#empty' => $this
        ->t('No Entries'),
    ];

    // Refresh resources via API row
    $api_refresh_row = [];
    $api_refresh_row['refresh_description'] = [
      '#markup' => '<h5>' . $this
        ->t('Refresh Project, Workflow, Vault, and Filter Information') . '</h5>' . '<p>' . $this
        ->t('This module locally caches the available projects, workflows, vaults, and filters. Use this utility whenever you need to pull down names for any newly created projects, workflows, vaults, or filters from the Lingotek Translation Management System.') . '</p>',
    ];
    $api_refresh_row['actions']['refresh_button'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Refresh'),
      '#button_type' => 'primary',
      '#submit' => [
        '::refreshResources',
      ],
    ];

    // Update Callback URL row
    $callback_url = $this
      ->configFactory()
      ->get('lingotek.settings')
      ->get('account.callback_url');
    $update_callback_url_row = [];
    $update_callback_url_row['update_description'] = [
      '#markup' => '<h5>' . $this
        ->t('Update Notification Callback URL') . '</h5>' . '<p>' . $this
        ->t('Update the notification callback URL. This can be run whenever your site is moved (e.g., domain name change or sub-directory re-location) or whenever you would like your security token re-generated.') . '</p>' . $this
        ->t('<b>Current notification callback URL:</b> %callback_url', [
        '%callback_url' => $callback_url,
      ]),
    ];
    $update_callback_url_row['actions']['update_url'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Update URL'),
      '#button_type' => 'primary',
      '#submit' => [
        '::updateCallbackUrl',
      ],
    ];

    // Disassociate All Translations row
    $disassociate_row = [];
    $disassociate_row['disassociate_description'] = [
      '#markup' => '<h5>' . $this
        ->t('Disassociate All Translations (use with caution)') . '</h5>' . '<p>' . $this
        ->t('Should only be used to change the Lingotek project or TM vault associated with the node’s translation. Option to disassociate node translations on Lingotek’s servers from the copies downloaded to Drupal. Additional translation using Lingotek will require re-uploading the node’s content to restart the translation process.') . '</p>',
    ];
    $disassociate_row['actions']['#type'] = 'actions';
    $disassociate_row['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Disassociate'),
      '#submit' => [
        '::disassociateAllTranslations',
      ],
      '#attributes' => [
        'class' => [
          'button',
          'button--danger',
        ],
      ],
    ];
    $debug_enabled = $this->state
      ->get('lingotek.enable_debug_utilities', FALSE);
    $enable_debug_utilities_row = [];
    $enable_debug_utilities_row['enable_debug_utilities_description'] = [
      '#markup' => '<h5>' . $this
        ->t('Debug utilities') . '</h5>' . '<p>' . $this
        ->t('Should only be used to debug Lingotek') . '</p>',
    ];
    $enable_debug_utilities_row['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $debug_enabled ? $this
        ->t('Disable debug operations') : $this
        ->t('Enable debug operations'),
      '#button_type' => 'primary',
      '#submit' => [
        '::switchDebugUtilities',
      ],
    ];
    $lingotek_table['api_refresh'] = $api_refresh_row;
    $lingotek_table['update_url'] = $update_callback_url_row;
    $lingotek_table['disassociate'] = $disassociate_row;
    $lingotek_table['enable_debug_utilities'] = $enable_debug_utilities_row;
    $form['utilities']['lingotek_table'] = $lingotek_table;
    return $form;
  }
  public function switchDebugUtilities() {
    $value = $this->state
      ->get('lingotek.enable_debug_utilities', FALSE);
    $this->state
      ->set('lingotek.enable_debug_utilities', !$value);
    $this->routeBuilder
      ->rebuild();
    $this
      ->messenger()
      ->addStatus($this
      ->t('Debug utilities has been %enabled.', [
      '%enabled' => !$value ? $this
        ->t('enabled') : $this
        ->t('disabled'),
    ]));
  }

  /**
   * Submit handler for refreshing the resources: projects, workflows, vaults,
   * and filters.
   */
  public function refreshResources() {
    $resources = $this->lingotek
      ->getResources(TRUE);
    $this
      ->messenger()
      ->addStatus($this
      ->t('Project, workflow, vault, and filter information have been refreshed.'));
  }
  public function disassociateAllTranslations(array &$form, FormStateInterface $form_state) {
    $form_state
      ->setRedirect('lingotek.confirm_disassociate');
  }
  public function updateCallbackUrl() {
    $new_callback_url = \Drupal::urlGenerator()
      ->generateFromRoute('lingotek.notify', [], [
      'absolute' => TRUE,
    ]);
    $config = $this
      ->configFactory()
      ->get('lingotek.settings');
    $configEditable = $this
      ->configFactory()
      ->getEditable('lingotek.settings');
    $configEditable
      ->set('account.callback_url', $new_callback_url);
    $configEditable
      ->save();
    $defaultProject = $config
      ->get('default.project');
    $new_response = $this->lingotek
      ->setProjectCallBackUrl($defaultProject, $new_callback_url);
    if ($new_response) {
      $this
        ->messenger()
        ->addStatus($this
        ->t('The callback URL has been updated.'));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::submitForm public function Form submission handler. Overrides FormInterface::submitForm 32
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
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. 3
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.
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 72
FormInterface::getFormId public function Returns a unique string identifying the form. 264
LingotekConfigFormBase::$lingotek protected property
LingotekConfigFormBase::$linkGenerator protected property The link generator.
LingotekConfigFormBase::$urlGenerator protected property The URL generator.
LingotekConfigFormBase::getEditableConfigNames public function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
LingotekSettingsTabUtilitiesForm::$routeBuilder protected property The route builder service.
LingotekSettingsTabUtilitiesForm::$state protected property
LingotekSettingsTabUtilitiesForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
LingotekSettingsTabUtilitiesForm::create public static function Instantiates a new instance of this class. Overrides LingotekConfigFormBase::create
LingotekSettingsTabUtilitiesForm::disassociateAllTranslations public function
LingotekSettingsTabUtilitiesForm::getFormID public function
LingotekSettingsTabUtilitiesForm::refreshResources public function Submit handler for refreshing the resources: projects, workflows, vaults, and filters.
LingotekSettingsTabUtilitiesForm::switchDebugUtilities public function
LingotekSettingsTabUtilitiesForm::updateCallbackUrl public function
LingotekSettingsTabUtilitiesForm::__construct public function Constructs a \Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm object. Overrides LingotekConfigFormBase::__construct
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. 27
MessengerTrait::messenger public function Gets the messenger. 27
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. 4
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.