Commit 326db646 authored by alexpott's avatar alexpott

Issue #2391217 by Berdir: Support base fields with multiple columns in entity queries

parent dbb32f2e
......@@ -165,7 +165,22 @@ public function addField($field, $type, $langcode) {
$entity_base_table = $entity_type->getBaseTable();
$entity_tables[$entity_base_table] = $this->getTableMapping($entity_base_table, $entity_type_id);
$sql_column = $specifier;
$table = $this->ensureEntityTable($index_prefix, $specifier, $type, $langcode, $base_table, $entity_id_field, $entity_tables);
// If there are more specifiers, get the right sql column name if the
// next one is a column of this field.
if ($key < $count) {
$next = $specifiers[$key + 1];
// Is this a field column?
$columns = $field_storage->getColumns();
if (isset($columns[$next]) || in_array($next, $table_mapping->getReservedColumns())) {
// Use it.
$sql_column = $table_mapping->getFieldColumnName($field_storage, $next);
// Do not process it again.
$key++;
}
}
$table = $this->ensureEntityTable($index_prefix, $sql_column, $type, $langcode, $base_table, $entity_id_field, $entity_tables);
// If there is a field storage (some specifiers are not, like
// default_langcode), check for case sensitivity.
......
......@@ -54,11 +54,10 @@ function menu_link_content_path_insert($path) {
function _menu_link_content_update_path_alias($path) {
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
// @todo Use link.uri once https://www.drupal.org/node/2391217 is in.
/** @var \Drupal\menu_link_content\MenuLinkContentInterface[] $entities */
$entities = \Drupal::entityManager()
->getStorage('menu_link_content')
->loadByProperties(['link__uri' => 'user-path:/' . $path]);
->loadByProperties(['link.uri' => 'user-path:/' . $path]);
foreach ($entities as $menu_link) {
$menu_link_manager->updateDefinition($menu_link->getPluginId(), $menu_link->getPluginDefinition(), FALSE);
}
......
......@@ -194,8 +194,7 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
$type_menus = $node_type->getThirdPartySetting('menu_ui', 'available_menus', array('main'));
if (in_array($menu_name, $type_menus)) {
$query = \Drupal::entityQuery('menu_link_content')
// @todo Use link.uri once https://www.drupal.org/node/2391217 is in.
->condition('link__uri', 'node/' . $node->id())
->condition('link.uri', 'node/' . $node->id())
->condition('menu_name', $menu_name)
->sort('id', 'ASC')
->range(0, 1);
......@@ -206,8 +205,7 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
// Check all allowed menus if a link does not exist in the default menu.
if (!$id && !empty($type_menus)) {
$query = \Drupal::entityQuery('menu_link_content')
// @todo Use link.uri once https://www.drupal.org/node/2391217 is in.
->condition('link__uri', 'entity:node/' . $node->id())
->condition('link.uri', 'entity:node/' . $node->id())
->condition('menu_name', array_values($type_menus), 'IN')
->sort('id', 'ASC')
->range(0, 1);
......
......@@ -13,6 +13,8 @@
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -669,4 +671,39 @@ public function testCaseSensitivity() {
}
/**
* Test base fields with multiple columns.
*/
public function testBaseFieldMultipleColumns() {
$this->enableModules(['taxonomy']);
$this->installEntitySchema('taxonomy_term');
Vocabulary::create(['vid' => 'tags']);
$term1 = Term::create([
'name' => $this->randomMachineName(),
'vid' => 'tags',
'description' => array(
'value' => $this->randomString(),
'format' => 'format1',
)]);
$term1->save();
$term2 = Term::create([
'name' => $this->randomMachineName(),
'vid' => 'tags',
'description' => array(
'value' => $this->randomString(),
'format' => 'format2',
)]);
$term2->save();
$ids = \Drupal::entityQuery('taxonomy_term')
->condition('description.format', 'format1')
->execute();
$this->assertEqual(count($ids), 1);
$this->assertEqual($term1->id(), reset($ids));
}
}
......@@ -247,8 +247,7 @@ function testBreadCrumbs() {
$this->drupalPostForm("admin/structure/menu/manage/$menu/add", $edit, t('Save'));
$menu_links = entity_load_multiple_by_properties('menu_link_content', array(
'title' => $edit['title[0][value]'],
// @todo Use link.uri once https://www.drupal.org/node/2391217 is in.
'link__uri' => 'user-path:/taxonomy/term/' . $term->id(),
'link.uri' => 'user-path:/taxonomy/term/' . $term->id(),
));
$tags[$name]['link'] = reset($menu_links);
$parent_mlid = $tags[$name]['link']->getPluginId();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment