Commit fc04b138 authored by Tim Bozeman's avatar Tim Bozeman Committed by Tim Bozeman
Browse files

Issue #3325340 by Tim Bozeman: Translation improvements

parent 78f9db42
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -92,10 +92,3 @@ function location_variant_module_implements_alter(&$implementations, $hook) {
function location_variant_form_variant_settings_alter(&$form, FormStateInterface $form_state, $form_id) {
  \Drupal::service('location_variant.variant_settings_form_alter')->alter($form, $form_state);
}

/**
 * Implements hook_views_query_alter().
 */
function location_variant_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  \Drupal::service('location_variant.view_handler')->viewsQueryAlter($view, $query);
}
+3 −15
Original line number Diff line number Diff line
@@ -58,6 +58,9 @@ class Variant extends RelationshipPluginBase {
  public function query() {
    $def = $this->definition;
    $id_key = $def['id_key'];
    $field_data_table = $def['field_data'];
    $variant_reference = $def['base'];
    $location_field = 'variant__locations';
    $language = $this->languageManager->getCurrentLanguage()->getId();

    if (!\str_contains($language, '-')) {
@@ -73,21 +76,6 @@ class Variant extends RelationshipPluginBase {
    $location_code = $info['location'];

    $locations = $this->locationHandler->getLocationLineage($location_code);
    // Are we in a workspace?
    $field_data_table = $def['field_data'];
    $variant_reference = $def['base'];
    $location_field = 'variant__locations';
    if ($this->moduleHandler->moduleExists('workspaces')) {
      $workspace_manager = \Drupal::service('workspaces.manager');
      if ($workspace_manager->hasActiveWorkspace()) {
        $field_data_table = $def['field_data_revision'];
        $variant_reference = $def['base_revision'];
        $location_field = 'variant_revision__locations';
        // Tag that we need to remove workspaces langcode condition.
        // @see location_variant_views_query_alter.
        $this->query->addTag("variant:$field_data_table");
      }
    }

    // Normally with a variation code like ko-2 you would extract the ko part
    // with SUBSTRING_INDEX(langcode, '-', 1). We need to be able to extract the
+0 −28
Original line number Diff line number Diff line
@@ -46,32 +46,4 @@ class ViewsLocationHandler {
    }
  }

  /**
   * Views query alter.
   *
   * Workspaces adds a language condition when it joins a revision table. Lets
   * remove that condition so that our Variant views relationship works.
   *
   * @see \Drupal\location_variant\Plugin\views\relationship\Variant
   *
   * @param \Drupal\views\ViewExecutable $view
   *   The view.
   * @param \Drupal\views\Plugin\views\query\QueryPluginBase $query
   *   The views query.
   *
   * @return void
   */
  public function viewsQueryAlter(ViewExecutable $view, QueryPluginBase $query) {
    foreach ($query->tags as $tag) {
      if (\str_contains($tag, 'variant')) {
        [, $field_revision_table] = explode(':', $tag);
        // Remove workspaces language condition so our variation relationship will
        // work.
        $join = $query->getTableQueue()[$field_revision_table]['join'];
        $join->extra = '';
        $join->extraOperator = '';
      }
    }
  }

}