diff --git a/core/modules/menu_link/src/Plugin/Field/FieldType/MenuLinkItem.php b/core/modules/menu_link/src/Plugin/Field/FieldType/MenuLinkItem.php index c1e1c8a..44591ed 100644 --- a/core/modules/menu_link/src/Plugin/Field/FieldType/MenuLinkItem.php +++ b/core/modules/menu_link/src/Plugin/Field/FieldType/MenuLinkItem.php @@ -31,6 +31,13 @@ * "title", "description", "weight" * } * }, + * "menu_name-parent" = { + * "label" = @Translation("Menu name and parent"), + * "translatable" = FALSE, + * "columns" = { + * "menu_name", "parent" + * } + * }, * }, * list_class = "\Drupal\menu_link\Plugin\Field\MenuLinkItemList", * ) diff --git a/core/modules/menu_link/src/Tests/MenuLinkApiTest.php b/core/modules/menu_link/src/Tests/MenuLinkApiTest.php new file mode 100644 index 0000000..7a5e64a --- /dev/null +++ b/core/modules/menu_link/src/Tests/MenuLinkApiTest.php @@ -0,0 +1,97 @@ +installEntitySchema('entity_test_mul'); + $this->installSchema('content_translation', 'content_translation'); + + $this->fieldStorage = FieldStorageConfig::create([ + 'field_name' => 'field_menu', + 'entity_type' => 'entity_test_mul', + 'type' => 'menu_link', + ]); + $this->fieldStorage->save(); + $this->field = FieldConfig::create([ + 'field_name' => 'field_menu', + 'entity_type' => 'entity_test_mul', + 'bundle' => 'entity_test_mul', + 'label' => 'menu', + 'required' => TRUE, + ]); + + + \Drupal::state()->set('entity_test_mul.bundles', ['entity_test_mul' => ['translatable' => TRUE]]); + + $groups = [ + 'menu_name-parent' => 0, + ]; + $this->field->setThirdPartySetting('content_translation', 'translation_sync', $groups); + $this->field->save(); + } + + public function testTranslationSaving() { + \Drupal::state()->set('entity_test_mul.bundles', ['entity_test_mul' => ['translatable' => TRUE]]); + \Drupal::service('content_translation.manager')->setEnabled('entity_test_mul', 'entity_test_mul', TRUE); + \Drupal::entityManager()->clearCachedBundles(); + + // Add an additional language. + ConfigurableLanguage::createFromLangcode('fr')->save(); + + $entity = EntityTestMul::create(['bundle' => 'entity_test']); + $entity->save(); + + $entity->field_menu->title = 'Menu link title'; + $entity->field_menu->description = 'test description'; + $entity->field_menu->menu_name = 'admin'; + $entity->field_menu->parent = 'system.admin'; + + $entity_translation = $entity->getTranslation('fr'); + $entity_translation->save(); + + // Ensure that values are synched between the translation and the original. + $entity_translation->field_menu->parent = 'system.admin_content'; + $entity_translation->save(); + + $entity = EntityTestMul::load($entity->id()); + $entity_translation = $entity->getTranslation('fr'); + + debug($entity->field_menu->parent); + debug($entity_translation->field_menu->parent); + } + +}