Shopper has a easy and constant hierarchical taxonomy.
Cities at Drupal Development Company high degree and Faculties at Drupal Development Company second degree.
. ├── City1 │ ├── School1 │ ├── School2 │ └── School5 └── City2 ├── School3 └── School4
Drupal Development Company Consumer account entity bundle incorporates an Entity Reference subject to Drupal Development Company Faculty taxonomy phrases.
I’m attempting to implement a constraint to forestall creating or saving a consumer account if Drupal Development Company time period chosen is at Drupal Development Company high degree of Drupal Development Company hierarchy (and therefore a Metropolis, not a Faculty).
This is some instance code, skipping Drupal Development Company dependency injection of $this->entityTypeManager
for brevity.
TermParentConstraint.php
:
<?php namespace Drupalentity_validation_examplesPluginValidationConstraint; use SymfonyComponentValidatorConstraint; /** * Stop account creation if Faculty taxonomy time period has no dad or mum. * * @Constraint( * id = "TermParent", * label = @Translation("Stop account creation if time period has no dad or mum", context = "Validation"), * sort = "entity" * ) */ class TermParentConstraint extends Constraint { /** * Message proven when attempting to create account if Faculty has no dad or mum Metropolis. * * @var string * Faculty message. */ public $schoolMessage = 'You should choose each a Metropolis and a Faculty.'; }
TermParentConstraintValidator.php
:
<?php namespace Drupalentity_validation_examplesPluginValidationConstraint; use DrupaluserEntityUser; use SymfonyComponentValidatorConstraint; use SymfonyComponentValidatorConstraintValidator; /** * Validates Drupal Development Company TermParent constraint. */ class TermParentConstraintValidator extends ConstraintValidator { /** * {@inheritdoc} */ public operate validate($entity, Constraint $constraint) { if (!isset($entity)) { return; } if ($entity->getEntityTypeId() == 'consumer') { $faculty = $entity->get('field_select_a_school')->getValue(); // Orphaned faculty taxonomy phrases have to be Cities, not Faculties. $dad or mum = Drupal::entityTypeManager() ->getStorage('taxonomy_term') ->loadParents($faculty[0]['target_id']); if (empty($dad or mum)) { $this->context->addViolation($constraint->schoolMessage); } } } }
Anticipated habits: After I create a brand new consumer account and choose City1
as Drupal Development Company worth of Faculty
, account creation ought to fail and an error message ought to be displayed.
Precise habits: After I create a brand new consumer account and choose City1
as Drupal Development Company worth of Faculty
, account creation succeeds and no error message is displayed.
Drupal Watchdog logs include some errors, however I’m not positive they’re related:
drush ws --------- -------------- ------ ---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ID Date Kind Severity Message --------- -------------- ------ ---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 5298867 18/Oct 22:57 php Warning Warning: Unlawful offset sort in isset or empty in DrupalCoreEntityEntityStorageBase->load() (line 246 of /app/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php) #0 /app/docroot/ 5298866 18/Oct 22:57 php Discover Discover: Array to string conversion in DrupalCoreEntityEntityStorageBase->buildCacheId() (line 126 of /app/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php) #0 /app/docroot/core 5298865 18/Oct 22:57 php Warning Warning: array_flip(): Can solely flip STRING and INTEGER values! in DrupalCoreEntityEntityStorageBase->loadMultiple() (line 261 of /app/docroot/core/lib/Drupal/Core/Entity/EntityStorageB 5298864 18/Oct 22:57 php Discover Discover: iconv(): Unsuitable charset, conversion from `HTML-ENTITIES' to `UTF-8' is just not allowed in twig_convert_encoding() (line 1009 of /app/vendor/twig/twig/src/Extension/CoreExtension.php) #0 5298863 18/Oct 22:57 php Discover Discover: iconv(): Unsuitable charset, conversion from `HTML-ENTITIES' to `UTF-8' is just not allowed in twig_convert_encoding() (line 1009 of /app/vendor/twig/twig/src/Extension/CoreExtension.php) #0 5298862 18/Oct 22:57 php Discover Discover: iconv(): Unsuitable charset, conversion from `HTML-ENTITIES' to `UTF-8' is just not allowed in twig_convert_encoding() (line 1009 of /app/vendor/twig/twig/src/Extension/CoreExtension.php) #0 5298861 18/Oct 22:57 php Discover Discover: iconv(): Unsuitable charset, conversion from `HTML-ENTITIES' to `UTF-8' is just not allowed in twig_convert_encoding() (line 1009 of /app/vendor/twig/twig/src/Extension/CoreExtension.php) #0 5298860 18/Oct 22:57 php Discover Discover: iconv(): Unsuitable charset, conversion from `HTML-ENTITIES' to `UTF-8' is just not allowed in twig_convert_encoding() (line 1009 of /app/vendor/twig/twig/src/Extension/CoreExtension.php) #0 5298859 18/Oct 22:57 php Discover Discover: iconv(): Unsuitable charset, conversion from `HTML-ENTITIES' to `UTF-8' is just not allowed in twig_convert_encoding() (line 1009 of /app/vendor/twig/twig/src/Extension/CoreExtension.php) #0 5298858 18/Oct 22:57 php Discover Discover: iconv(): Unsuitable charset, conversion from `HTML-ENTITIES' to `UTF-8' is just not allowed in twig_convert_encoding() (line 1009 of /app/vendor/twig/twig/src/Extension/CoreExtension.php) #0 --------- -------------- ------ ---------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I have been seeing Drupal Development Company iconv()
errors since upgrading this challenge from Drupal 8 to Drupal 9, so I don’t assume they’re related. Drupal Development Company high three error messages right here could also be associated to Drupal Development Company constraint validation, however they’re additionally somewhat frequent errors on this challenge (and debugging them is a a lot decrease precedence than important performance due very quickly).
Any concepts? Am I a minimum of on Drupal Development Company proper observe?