translateFilters example

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

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $filters = $this->translateFilters();
    $filter_values = $this->translateFilterValues();

    $form['#attached']['library'][] = 'locale/drupal.locale.admin';

    $form['filters'] = [
      '#type' => 'details',
      '#title' => $this->t('Filter translatable strings'),
      '#open' => TRUE,
      '#attributes' => ['class' => ['clearfix']],
    ];
    foreach ($filters as $key => $filter) {
      

  protected function translateFilterValues($reset = FALSE) {
    if (!$reset && static::$filterValues) {
      return static::$filterValues;
    }

    $filter_values = [];
    $filters = $this->translateFilters();
    $request = $this->getRequest();
    $session_filters = $request->getSession()->get('locale_translate_filter', []);
    foreach ($filters as $key => $filter) {
      $filter_values[$key] = $filter['default'];
      // Let the filter defaults be overwritten by parameters in the URL.       if ($request->query->has($key)) {
        // Only allow this value if it was among the options, or         // if there were no fixed options to filter for.         $value = $request->query->get($key);
        if (!isset($filter['options']) || isset($filter['options'][$value])) {
          $filter_values[$key] = $value;
        }
Home | Imprint | This part of the site doesn't use cookies.