Updated: Comment #N

Problem/Motivation

DiscoveryInterface::getDefinition() returns NULL when a plugin ID cannot be found.
#2168333: Ensure custom EntityType controllers can be provided by modules adds an optional parameter, defaulting to FALSE, that when TRUE throws an exception instead of returning NULL

Proposed resolution

Move this optional parameter to the interface and all subclasses.

Remaining tasks

User interface changes

N/A

API changes

None yet.

CommentFileSizeAuthor
#84 plugin-2178795-84.patch737 bytestim.plunkett
#80 interdiff-2178795-77-80.txt398 bytesyesct
#80 drupal_2178795_80.patch48.91 KByesct
#77 interdiff.txt945 bytesjlbellido
#77 drupal_2178795_77.patch48.91 KBjlbellido
#69 drupal_2178795_69.patch49.65 KBxano
#69 interdiff.txt3.87 KBxano
#62 drupal_2178795_62.patch43.31 KBxano
#62 interdiff.txt6.89 KBxano
#58 plugin-exception-2178795-58.patch44.87 KBtim.plunkett
#57 interdiff.txt2.02 KBtim.plunkett
#57 plugin-exception-2178795-57.patch54.57 KBtim.plunkett
#54 interdiff.txt12.75 KBtim.plunkett
#54 discovery-2178795-54.patch53.55 KBtim.plunkett
#51 interdiff-49-51.txt831 bytesyesct
#51 drupal_2178795_51.patch54.47 KByesct
#49 drupal_2178795_49.patch54.54 KBberdir
#46 drupal_2178795_46.patch54.7 KBxano
#40 discovery-2178795-40.patch54.54 KBtim.plunkett
#39 discovery-2178795-39.patch54.52 KBtim.plunkett
#38 discovery-2178795-38.patch54.52 KBtim.plunkett
#38 interdiff.txt2.33 KBtim.plunkett
#36 discovery-2178795-36.patch53.24 KBtim.plunkett
#36 interdiff.txt786 bytestim.plunkett
#32 interdiff.txt4.92 KBtim.plunkett
#32 discovery-2178795-32.patch52.89 KBtim.plunkett
#30 discovery-2178795-30.patch52.88 KBtim.plunkett
#29 discovery-2178795-29.patch53.23 KBtim.plunkett
#27 interdiff.txt1.81 KBtim.plunkett
#27 discovery-2178795-27.patch52.98 KBtim.plunkett
#25 interdiff.txt1.12 KBtim.plunkett
#25 discovery-2178795-25.patch53.64 KBtim.plunkett
#24 interdiff.txt5.34 KBtim.plunkett
#24 discovery-2178795-24.patch53.74 KBtim.plunkett
#21 interdiff.txt9.27 KBtim.plunkett
#21 discovery-2178795-21.patch49.35 KBtim.plunkett
#19 interdiff.txt1.23 KBtim.plunkett
#19 discovery-2178795-19.patch48.19 KBtim.plunkett
#16 discovery-2178795-16.patch47.86 KBtim.plunkett
#15 interdiff.txt6.39 KBtim.plunkett
#15 discovery-2178795-15.patch47.81 KBtim.plunkett
#13 interdiff.txt3.4 KBtim.plunkett
#13 discovery-2178795-13.patch41.43 KBtim.plunkett
#11 interdiff.txt5.21 KBtim.plunkett
#11 plugin-2178795-11.patch38.02 KBtim.plunkett
#9 interdiff.txt2.57 KBtim.plunkett
#9 plugin-exception-2178795-8.patch32.81 KBtim.plunkett
#4 interdiff.txt10.13 KBtim.plunkett
#4 discovery-2178795-4-TRUE.patch30.24 KBtim.plunkett
#4 discovery-2178795-4-FALSE.patch28.56 KBtim.plunkett

Comments

yched’s picture

Meaning we'd need a hasDefinition() method for simple existence checks ?

berdir’s picture

Not having an argument at all would require that method. But having that method might be a good idea anyway, as if ($manager->hasDefininition()) makes more sense than getDefinition().

I'd vote for having the argument and default to TRUE (throwing exception). That's the same behavior as $container->get().

dawehner’s picture

Consider making it default to TRUE, or just making that the actual expected behavior, and never return NULL

A non existing plugin is certainly not the code path you expect to have, so an exception is a good tool here.

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new28.56 KB
new30.24 KB
new10.13 KB

Here's two patches, one keeping the default as FALSE, the other as TRUE. Depending on how many failures we have for TRUE, we can decide what to do.

Also, the abstract base classes for the exception throwing should just be a trait, but we still can't do that yet.

Status: Needs review » Needs work

The last submitted patch, 4: discovery-2178795-4-TRUE.patch, failed testing.

The last submitted patch, 4: discovery-2178795-4-TRUE.patch, failed testing.

The last submitted patch, 4: discovery-2178795-4-FALSE.patch, failed testing.

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

Hm, not too bad. I'll be looking into this tonight.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new32.81 KB
new2.57 KB

Going to double down on defaulting to TRUE, it's much better for DX and seems to be the expectation.

#2143057: DefaultPluginManager::getDefinition() violates interface has the fix for DateTimeItemTest, but this issue also encompasses that fix, so I'm going to mark it as a dupe.

Many of the other fails were because field_test uses the 'entity_test' entity type, but doesn't always enable entity_test.module. How that works is beyond me.

Finally, #1875992: Add EntityFormDisplay objects for entity forms moved a bunch of code around, and turned 'text_textfield' into 'text_text', which somehow didn't break until now...

There might have been other fails, but that text_text one was a LOT of the time, so just sending this to the bot.

Status: Needs review » Needs work

The last submitted patch, 9: plugin-exception-2178795-8.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new38.02 KB
new5.21 KB

I think the InstallUninstallTest failures are actually #2155635: Allow plugin managers to opt in to cache clear during module install, which sucks.

This should fix the rest.

Status: Needs review » Needs work

The last submitted patch, 11: plugin-2178795-11.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new41.43 KB
new3.4 KB

Oh, or maybe it was just FieldTypePluginManager

Status: Needs review » Needs work

The last submitted patch, 13: discovery-2178795-13.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new47.81 KB
new6.39 KB

Ugh. Because they are exceptions, it interrupts the rest of the test. So we can only find one at a time...
Adding to all places that wrap getDefinition() in an if(), they definitely want NULL instead.

tim.plunkett’s picture

Status: Needs review » Needs work

The last submitted patch, 16: discovery-2178795-16.patch, failed testing.

The last submitted patch, 16: discovery-2178795-16.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new48.19 KB
new1.23 KB

Ah, in #2184951: Allow plugins to declare themselves a derivative there is a first check to getDefinition on the full $plugin_id, and not just on the $base_plugin_id. That one will usually fail, and is only used for overrides. The second call on the $base_plugin_id will always happen, and is the correct place to (possibly) throw an exception.

Added a comment to that effect.

yched’s picture

+++ b/core/modules/edit/lib/Drupal/edit/EditController.php
@@ -108,7 +108,7 @@ public function metadata(Request $request) {
-      if (!$entity_type || !$this->entityManager()->getDefinition($entity_type)) {
+      if (!$entity_type || !$this->entityManager()->getDefinition($entity_type, FALSE)) {

+++ b/core/modules/entity_reference/entity_reference.module
@@ -198,7 +198,7 @@ function entity_reference_query_entity_reference_alter(AlterableInterface $query
-  if (!\Drupal::service('plugin.manager.field.field_type')->getDefinition('entity_reference')) {
+  if (!\Drupal::service('plugin.manager.field.field_type')->getDefinition('entity_reference', FALSE)) {

+++ b/core/modules/field/field.views.inc
@@ -112,7 +112,7 @@ function field_views_field_default_views_data(FieldInterface $field) {
-  if (!\Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType())) {
+  if (!\Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType(), FALSE)) {

+++ b/core/modules/field/lib/Drupal/field/FieldInfo.php
@@ -438,7 +438,7 @@ public function getBundleInstances($entity_type, $bundle) {
-    if (\Drupal::entityManager()->getDefinition($entity_type) && !empty($field_map[$entity_type])) {
+    if (\Drupal::entityManager()->getDefinition($entity_type, FALSE) && !empty($field_map[$entity_type])) {

+++ b/core/modules/edit/lib/Drupal/edit/Access/EditEntityAccessCheck.php
@@ -64,7 +64,7 @@ protected function validateAndUpcastRequestAttributes(Request $request) {
-      if (!$entity_type || !$this->entityManager->getDefinition($entity_type)) {
+      if (!$entity_type || !$this->entityManager->getDefinition($entity_type, FALSE)) {

+++ b/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php
@@ -64,7 +64,7 @@ protected function validateAndUpcastRequestAttributes(Request $request) {
-      if (!$entity_type || !$this->entityManager->getDefinition($entity_type)) {
+      if (!$entity_type || !$this->entityManager->getDefinition($entity_type, FALSE)) {

Still +1 on a hasDefinition($plugin_id) ?

tim.plunkett’s picture

StatusFileSize
new49.35 KB
new9.27 KB

Fine by me.

Status: Needs review » Needs work

The last submitted patch, 21: discovery-2178795-21.patch, failed testing.

The last submitted patch, 21: discovery-2178795-21.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new53.74 KB
new5.34 KB

I had a condition backwards, but also found a nice place to encapsulate a field exception.

tim.plunkett’s picture

StatusFileSize
new53.64 KB
new1.12 KB

Eh, let's not copy all of that boilerplate.

yched’s picture

+++ b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php
@@ -104,4 +105,25 @@ public function getConfigurableDefinitions() {
+  public function getDefinition($plugin_id, $exception_on_invalid = TRUE) {
...
+    throw new FieldException(format_string('Attempt to create a field of unknown type %type.', array('%type' => $plugin_id)));

+++ b/core/modules/field/lib/Drupal/field/Entity/Field.php
@@ -327,9 +327,6 @@ protected function preSaveNew(EntityStorageControllerInterface $storage_controll
-    if (!$field_type) {
-      throw new FieldException(format_string('Attempt to create a field of unknown type %type.', array('%type' => $this->type)));
-    }

Hm - not sure why we'd want to do that ?
Plus, there might be places that call FieldTypePM::getDefinition($unknow_plugin_id) but are not "attempting to create a field" ?

I'd tend to leave FieldTypePM::getDefinition() untouched / non-overriden, and have Field::preSaveNew() catch the generic plugin exception and throw its more specific one ?

tim.plunkett’s picture

StatusFileSize
new52.98 KB
new1.81 KB

Hrmmmmmmm fair enough, since the exception message is a bit overspecific.

I'll just pass FALSE and avoid the overhead of catching the exception.

neclimdul’s picture

Seems like I've seen this code before. I was leaning toward just making this the default functionality but that would be bad for derivatives.

So, seems like this is a useful addition. +1

tim.plunkett’s picture

StatusFileSize
new53.23 KB

After further discussion with @neclimdul and @msonnabaum, I tried out patches where it always threw an exception, and another where we used a constant instead of TRUE/FALSE. Both of those were way more unwieldy than this, and with no real gain. So, sticking with this.

It needed a reroll after #2185831: Split up ParamConverterManager and stop throwing NotFoundHttpException for the edit access checks, no changes.

tim.plunkett’s picture

StatusFileSize
new52.88 KB

Git context conflict with #2175415: Add FieldTypePluginManagerInterface, no changes.

Status: Needs review » Needs work

The last submitted patch, 30: discovery-2178795-30.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new52.89 KB
new4.92 KB

Status: Needs review » Needs work

The last submitted patch, 32: discovery-2178795-32.patch, failed testing.

The last submitted patch, 32: discovery-2178795-32.patch, failed testing.

The last submitted patch, 32: discovery-2178795-32.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new786 bytes
new53.24 KB

Status: Needs review » Needs work

The last submitted patch, 36: discovery-2178795-36.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new2.33 KB
new54.52 KB

I don't know how to use returnValueMap with a parameter that might be TRUE or FALSE. $this->isType('bool') doesn't work there. Switching to returnCallback.

tim.plunkett’s picture

StatusFileSize
new54.52 KB
tim.plunkett’s picture

StatusFileSize
new54.54 KB
eclipsegc’s picture

I will call out some things I don't like here, namely the addition of yet more base class things to inherit from. Traits would really clean this up, and while I know we all know that, I'm going to call it out so that we have yet another place where traits could make things less WTF. That being said the basic functionality here is very sensible to me.

A few nitpicks, otherwise I'm generally ++ to this.

  1. +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php
    @@ -54,7 +54,7 @@ public function getPropertyDefinitions() {
    -      static::$propertyDefinitions['date'] = DataDefinition::create('datetime_computed')
    +      static::$propertyDefinitions['date'] = DataDefinition::create('any')
    

    Why'd this change?

  2. +++ b/core/modules/field/tests/modules/field_test/field_test.info.yml
    @@ -5,3 +5,5 @@ core: 8.x
    +dependencies:
    +  - entity_test
    

    What about this patch caused new dependencies to be needed for this test?

  3. +++ b/core/modules/system/tests/modules/entity_test/entity_test.install
    @@ -32,7 +32,7 @@ function entity_test_install() {
    -      ->setComponent('field_test_text', array('type' => 'text_text'))
    +      ->setComponent('field_test_text', array('type' => 'text_textfield'))
    

    Why'd this change?

Not going to change the status cause these could be completely justified. Please just gimme a couple explanations here and I'd be happy to rtbc this.

Eclipse

tim.plunkett’s picture

For #41.1 and 41.3, see #2143057: DefaultPluginManager::getDefinition() violates interface. They're just wrong, and it silently fails in HEAD. Throwing an exception reveals the bug.

Same thing actually for #41.2, many many many tests that only enable field_test use the test entity types in entity_test, and it just silently returns NULL.

eclipsegc’s picture

Status: Needs review » Reviewed & tested by the community

That is perfectly sensible.

Eclipse

neclimdul’s picture

+1 to RTBC

Still have the thoughts/concerns from #29 but as Tim said they make things worse right now so this is the correct approach.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

discovery-2178795-40.patch no longer applies.

error: patch failed: core/modules/field/field.views.inc:67
error: core/modules/field/field.views.inc: patch does not apply

xano’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new54.7 KB

Re-roll, and I made the following minor change while re-rolling this particular line:
From:

  if ($entity_manager->getDefinition($field->entity_type) && $entity_manager->getStorageController($field->entity_type) instanceof FieldableDatabaseStorageController) {
    return TRUE;
  }

to:

  return $entity_manager->hasDefinition($field->entity_type) && $entity_manager->getStorageController($field->entity_type) instanceof FieldableDatabaseStorageController;
neclimdul’s picture

Status: Needs review » Reviewed & tested by the community

Agreed, that is appropriate. The docs only document the true case and null is falsy but this is more correct for returning a bool.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

drupal_2178795_46.patch no longer applies.

error: patch failed: core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php:54
error: core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php: patch does not apply

berdir’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new54.54 KB

Re-roll, conflicted in DateTimeItem.

yesct’s picture

Issue tags: -Needs reroll

applies fine.

  1. +++ b/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryInterface.php
    @@ -18,11 +18,18 @@
    +   * @param bool $exception_on_invalid
    +   *   (optional) If TRUE, an invalid plugin ID will throw an exception.
    +   *   Defaults to FALSE.
    ...
    +  public function getDefinition($plugin_id, $exception_on_invalid = TRUE);
    

    defaults to true. Also we dont have to give the defaults anymore (we used to, but dont now) according to 1354. https://drupal.org/node/1354#param

  2. +++ b/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryInterface.php
    @@ -18,11 +18,18 @@
        * @return mixed
    -   *   A plugin definition, or NULL if no definition was found for $plugin_id.
    +   *   A plugin definition, or NULL if the plugin ID is invalid and
    +   *   $exception_on_invalid is TRUE.
    
    +++ b/core/lib/Drupal/Component/Plugin/Discovery/StaticDiscoveryDecorator.php
    @@ -41,14 +41,14 @@ public function __construct(DiscoveryInterface $decorated, $registerDefinitions
    -  public function getDefinition($base_plugin_id) {
    
    +++ b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php
    @@ -8,11 +8,12 @@
      */
    

    if an exception is thrown, then uh... it wont be able to return, right? so I'm thinking this is NULL if it's invalid and exception_on_invalid is FALSE.

  3. +++ b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php
    @@ -195,28 +195,16 @@ public function getBundleInfo($entity_type);
    +   * {@inheritdoc}
        *
        * @return \Drupal\Core\Entity\EntityTypeInterface|null
    ...
       /**
    -   * Returns an array of entity type info, keyed by entity type name.
    +   * {@inheritdoc}
        *
        * @return \Drupal\Core\Entity\EntityTypeInterface[]
    -   *   An array of entity type objects.
        */
       public function getDefinitions();
    

    why are these leaving the @return? should just be fine with {@inheritdoc}, right?

yesct’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new54.47 KB
new831 bytes

here is a patch that just takes out that (incorrect) defaults to, and fixes the return details.

Status: Needs review » Needs work

The last submitted patch, 51: drupal_2178795_51.patch, failed testing.

tim.plunkett’s picture

+++ b/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryBase.php
@@ -0,0 +1,64 @@
+/**
+ * Contains a base class for discovery.
+ *
+ * @todo Replace with a trait.

Oh I forgot about this!

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
Status: Needs work » Needs review
StatusFileSize
new53.55 KB
new12.75 KB

Okay, let's see how this goes.

Status: Needs review » Needs work

The last submitted patch, 54: discovery-2178795-54.patch, failed testing.

eclipsegc’s picture

Probably need to declare and abstract getDefinitions() method on the DiscoveryTrait.

Eclipse

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new54.57 KB
new2.02 KB

Good point!
Fixed the tests as well.

tim.plunkett’s picture

Priority: Normal » Major
StatusFileSize
new44.87 KB

I was really surprised today when I realized this hadn't gone in yet.

This was RTBC before, and is a big win IMO.

tim.plunkett’s picture

+++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php
@@ -46,7 +46,7 @@ public static function propertyDefinitions(FieldDefinitionInterface $field_defin
+    $properties['date'] = DataDefinition::create('any')

+++ b/core/modules/forum/forum.install
@@ -91,8 +91,7 @@ function forum_install() {
 function forum_module_preinstall($module) {

+++ b/core/modules/system/tests/modules/entity_test/entity_test.install
@@ -32,7 +32,7 @@ function entity_test_install() {
-      ->setComponent('field_test_text', array('type' => 'text_text'))
+      ->setComponent('field_test_text', array('type' => 'text_textfield'))

The patch is smaller because hunks like these were committed in other issues.

Status: Needs review » Needs work

The last submitted patch, 58: plugin-exception-2178795-58.patch, failed testing.

berdir’s picture

+++ b/core/modules/entity_reference/entity_reference.module
@@ -204,7 +204,7 @@ function entity_reference_query_entity_reference_alter(AlterableInterface $query
  */
 function entity_reference_create_instance($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = 1) {
   // If a field type we know should exist isn't found, clear the field cache.
-  if (!\Drupal::service('plugin.manager.field.field_type')->getDefinition('entity_reference')) {
+  if (!\Drupal::service('plugin.manager.field.field_type')->hasDefinition('entity_reference')) {
     field_cache_clear();
   }

Pretty sure that this is dead code now with the standardized plugin cache clearer...

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new6.89 KB
new43.31 KB

I removed the optional exceptions like we did back in #1846070: Improve exception messages when plugins cannot be found, because if you don't want an exception, you should have used hasDefinition() first. This way we also don't have to change the interface, and we keep our API simple and consistent.

Status: Needs review » Needs work

The last submitted patch, 62: drupal_2178795_62.patch, failed testing.

sun’s picture

if you don't want an exception, you should have used hasDefinition()

+1, most sane and most sensible approach.

tim.plunkett’s picture

That was the direction of the OP. See #1 and #2.

Also, your patch makes zero changes to the actual calling code, if you want to hijack an issue at least make the necessary changes correctly.

xano’s picture

That was the direction of the OP. See #1 and #2.

Not everybody agrees on that approach, so I wanted to propose an alternative.

Also, your patch makes zero changes to the actual calling code, if you want to hijack an issue at least make the necessary changes correctly.

I didn't want to spend time on something that did not seem important for demonstrating my proposal. If the approach I suggested will be accepted, then I will gladly finish the conversion. Please be careful when you tell people they hijacked issues. It's not motivating.

tim.plunkett’s picture

I meant, your most recent patch matches the OP. And we have since diverged from that approach...

xano’s picture

I'll work on an improved version of #58.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new3.87 KB
new49.65 KB

This patch follows #58.

yesct’s picture

Ah, ok, so #62 was not pursued and back to getting #58 to pass. ok.

  1. +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
    @@ -112,7 +112,7 @@ function manageFieldsPage($type = '') {
    -    $this->assertIdentical("$url/delete", (string) $result[2]['href']);
    +    $this->assertIdentical("$url/delete", (string) $result[3]['href']);
    

    why? what is result[2] now?

  2. +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCckFieldRevisionTest.php
    @@ -19,7 +19,7 @@ class MigrateCckFieldRevisionTest extends MigrateNodeTestBase {
    -  public static $modules = array('node', 'text');
    +  public static $modules = array('field', 'filter', 'node', 'text');
    
    +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayFeedTest.php
    @@ -26,7 +26,7 @@ class DisplayFeedTest extends PluginTestBase {
    -  public static $modules = array('node', 'views_ui');
    +  public static $modules = array('block', 'node', 'views_ui');
    

    why is *this* issue revealing that we need to declare that migrate and display tests need to enable field, filter and block?

    field kinda makes sense, but filter and block? because they provide fields....? that were expected? but when they were not there, null was returned before and now we are throwing exception? so we had tests that were not really testing what we thought they were?

xano’s picture

why? what is result[2] now?

Because entity_test.module is enabled now, it adds an additional entity operation between the other ones. I'm not sure the test should test for the order of operations. Should we just assert whether the correct URL exists on the page instead, or is order really important here?

why is *this* issue revealing that we need to declare that migrate and display tests need to enable field, filter and block?

Many of the other fails were because field_test uses the 'entity_test' entity type, but doesn't always enable entity_test.module. How that works is beyond me.

-@tim.plunkett in #9.
This may be related. I found out the test needed Text's field, and as Text depends on Field and Filter, and Simpletest does not enable dependencies automatically, I had to add all of them here.

yesct’s picture

Issue tags: +Novice
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCckFieldRevisionTest.php
@@ -19,7 +19,7 @@ class MigrateCckFieldRevisionTest extends MigrateNodeTestBase {
diff --git a/core/modules/simpletest/files/.htaccess b/core/modules/simpletest/files/.htaccess

oops I this should not have been included.

-----
Novice task to make a new patch to take out that file. (the issue is not novice but making a new patch with just the needed files is)
https://drupal.org/contributor-tasks/create-patch

yesct’s picture

Status: Needs review » Needs work
yesct’s picture

Issue tags: +Traits
Related issues: +#2134513: [policy, no patch] Trait strategy
jlbellido’s picture

Issue tags: +DrupalCampSpain

I'll do #72

jlbellido’s picture

Assigned: Unassigned » jlbellido
jlbellido’s picture

Status: Needs work » Needs review
StatusFileSize
new48.91 KB
new945 bytes

Just Re-rolled #69 and deleted the .htaccess file from core/modules/simpletest/files/ in #69 as @YesCT said in #72

Thanks!

yesct’s picture

Assigned: jlbellido » Unassigned
Issue summary: View changes
Issue tags: -Novice

removing novice tag since that one novice task was done. thanks @jlbellido

Seems like the remaining task here is a review.

tim.plunkett’s picture

I would RTBC this myself if it weren't predominately my patch. Thanks @jlbellido!

yesct’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new48.91 KB
new398 bytes

looked at the diff of the last couple patches and it seems @jlbellido added a blank line accidentally. removing that.

looked at this whole thing again, rtbc from me.

cordoval’s picture

just some comments as i read through, if bad ones please disregard

  1. +++ b/core/lib/Drupal/Core/Entity/EntityManager.php
    @@ -312,7 +312,7 @@ public function getController($entity_type, $controller_type, $controller_class_
    +    if (($entity_type = $this->getDefinition($entity_type_id, FALSE)) && $admin_form = $entity_type->getLinkTemplate('admin-form')) {
    

    why the () around $entity_type = .. ? i don't think you need them?

  2. +++ b/core/lib/Drupal/Core/Entity/EntityManagerInterface.php
    @@ -274,28 +274,16 @@ public function getExtraFields($entity_type_id, $bundle);
    +  public function getDefinition($entity_type_id, $exception_on_invalid = TRUE);
    

    you changed the false to true here, is that fine?

  • Commit 6261377 on 8.x by webchick:
    Issue #2178795 by tim.plunkett, jlbellido, YesCT, Berdir, Xano: Allow...
webchick’s picture

Status: Reviewed & tested by the community » Fixed

I had a pretty hilarious exchange in IRC with timplunkett while reading this patch where I basically repeated everything I said about not liking the optional parameter in #2168333-54: Ensure custom EntityType controllers can be provided by modules. Oh, well, at least I'm consistent, even if I have the memory of a goldfish. :P~

It doesn't really make sense though to have one type of plugin use this method of error trapping and the rest not, given this has buy-in from all of the plugin subsystem maintainers from what I can see. The DIscoveryTrait is nice. I also like the fact that it defaults to TRUE (meaning, show the exception), which IMO is what you'd expect. I'm still a bit worried about what this will do to existing contrib modules out there though, since that FALSE parameter had to be stuck in some pretty innocuous places in the patch.

Nevertheless, I think this is good to go in, since it makes an existing situation in HEAD a tad bit nicer/more consistent.

Committed and pushed to 8.x. Thanks!

tim.plunkett’s picture

Title: Allow DiscoveryInterface::getDefinition() to throw an exception for an invalid plugin » [HEAD BROKEN] Allow DiscoveryInterface::getDefinition() to throw an exception for an invalid plugin
Status: Fixed » Reviewed & tested by the community
StatusFileSize
new737 bytes

This was retested today... But somehow still conflicted with #2039435: Convert EntityManager to extend DefaultPluginManager in a phpunit test.
This doesn't need to wait for a bot run, its a PHPUnit test:
$ vendor/bin/phpunit ./tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php

I also ran all phpunit tests locally.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

Committed and pushed hotfix to 8.x.

  • Commit a2177ab on 8.x by webchick:
    Issue #2178795 follow-up by tim.plunkett: Fix conflict with recently...
tim.plunkett’s picture

Title: [HEAD BROKEN] Allow DiscoveryInterface::getDefinition() to throw an exception for an invalid plugin » Allow DiscoveryInterface::getDefinition() to throw an exception for an invalid plugin

Thanks for the quick turnaround.

Status: Fixed » Needs work

The last submitted patch, 84: plugin-2178795-84.patch, failed testing.

berdir’s picture

Status: Needs work » Fixed

Already committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.