Problem/Motivation
In testing #1876394: You have to specify $node->changed when comment.module is enabled. using
No title given
drush @drupal.d8 php-eval "\$node = entity_create('node', array('type' => 'page'));\$node->save();"
a node is created without the required title field.
Even calling $node->validate(); does not help preventing the node saved.
drush @drupal.d8 php-eval "\$node = entity_create('node', array('type' => 'page')); \$node->validate(); \$node->save();"
Bogus bundle name
Creating a node with non existing type 'bogus' is also possible. Calling $node->validate(); throws an exception.
drush @drupal.d8 php-eval "\$node = entity_create('node', array('type' => 'bogus'));\$node->save();"
drush @drupal.d8 php-eval "\$node = entity_create('node', array('type' => 'bogus')); \$node->validate(); \$node->save();"
gives
exception 'Drupal\Component\Plugin\Exception\PluginNotFoundException' with message 'The "entity:node:bogus" plugin does not exist.' in /Users/clemens/Sites/drupal/d8/www/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php:57 [error]
Proposed resolution
Make sure an entity is validated before saving it.
Make sure validate checks for required title field.
Remaining tasks
User interface changes
API changes
Comments
Comment #1
clemens.tolboomExecuting validation before saving fixes for invalid content type but not for the required title.
Comment #2
clemens.tolboomSetting component to entity system.
It seems to me title field is required and it's default value is an empty string "" which is not what I read/debug from
\Drupal\Core\TypedData\Plugin\DataType\Map::isEmpty
\Drupal\Core\TypedData\Plugin\DataType\ItemList::isEmpty
esp. the latter
but we do have an empty string "".
(next to test is bogus bundle)
Comment #3
clemens.tolboomChecking with core/tests/Drupal/Tests/Core/Validation/Plugin/Validation/Constraint/PrimitiveTypeConstraintValidatorTest.php we don't have covert values like NULL, 2e12,etc. NULL is an acceptable value so should be coverted.
Attached patch adds more tests but with outcomes to be discussed.
Comment #4
clemens.tolboom(Previous patch contained too much diff)
Why are 4 and 0.5 not valid? Casting these (bool) should lead to TRUE
These too currently FAIL running
Should all these pass or fail? The comment suggested they should fail. If so we must fix this.
Comment #5
clemens.tolboomThis is still the case. Visiting the frontpage with empty title I get
Comment #6
clemens.tolboomAdded the $node->validate() to the examples.
Comment #7
mgiffordPatch no longer applies.
Comment #8
cilefen commentedComment #12
jp.stacey commentedFor reference, I'm still getting this bug: specifically when I run the /upgrade UI from an old Drupal 6 site. Of 16 D6 nodes with type=review, I end up with 15 fine, but the first D8 review node to be migrated (nid=1) has type=5 (i.e. the numeric string "5".)
This happens on a fresh Drupal install (although I am also using Migrate Plus and Tools, both 8.x-3.0-beta1, so perhaps they bypass something that Drupal core might prevent?)
Comment #19
matroskeenThis is applicable to other entity types as well. Example: #2994657: It is possible to create taxonomy terms for vocabularies that do not exist.
Comment #24
mohit_aghera commentedI came across this issue while doing bugsmash triage.
This issue doesn't seem to be reproducible anymore.
I tried to do that in latest 11.x and got the following error.
Please re-open again if you still notice the issue.