ConstraintValidator fails to validate constraint on Taxonomy Time period reference subject

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?

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

ConstraintValidator fails to validate constraint on Taxonomy Time period reference subject

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.