Problem

Feed entity validation misses the logic from FeedForm::validate(). This is critical as the validation logic will be missed from RESTful validation. (see #1696648: [META] Untie content entity validation from form validation)

Proposed resolution

Convert the logic to entity validation and leverage entity validation in form validation.

Remaining tasks

Implement proposed resolution.

User interface changes

-

API changes

-

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

larowlan’s picture

Assigned: Unassigned » larowlan

taking

larowlan’s picture

Status: Active » Needs review
FileSize
9.9 KB
larowlan’s picture

Assigned: larowlan » Unassigned
dawehner’s picture

+++ b/core/modules/aggregator/src/Plugin/Validation/Constraint/FeedConstraintValidatorBase.php
@@ -0,0 +1,70 @@
+  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+    return new static($container->get('entity_manager')->getStorage('aggregator_feed'));
+  }
+
+  /**
+   * Returns the feed storage handler.
+   *
+   * @return \Drupal\aggregator\FeedStorageInterface|\Drupal\Core\Entity\EntityStorageInterface
+   *   The feed storage handler.
+   */
+  protected function feedStorage() {
+    if (!$this->feedStorage) {
+      $this->feedStorage = \Drupal::entityManager()->getStorage('aggregator_feed');
+    }
+    return $this->feedStorage;
+  }

Why do we need both?

Berdir’s picture

Any chance we can find a way to write a generic unique field constraint? I know that for example BlockContent needs that too.

And there's nothing in FeedStorage::getFeedDuplicates() that is feed specific, it's just an entity query?

larowlan’s picture

Why do we need both?

Cause it no-worky. See #2197029: Allow to inject dependencies into validation constraints

Any chance we can find a way to write a generic unique field constraint?

Sure but should we do that as a non-critical follow up?

ParisLiakos’s picture

And there's nothing in FeedStorage::getFeedDuplicates() that is feed specific, it's just an entity query?

yes. relevant: #2228733: Remove getFeedDuplicates - its unused and untested

larowlan’s picture

Should we postpone this on #2197029: Allow to inject dependencies into validation constraints to address comment #4?

larowlan’s picture

Issue tags: +CriticalADay
fago’s picture

There is already a UserUniqueValidator - it should be easy to make this unique-constraint entity type acgnostic. If some usages needs customized messages, those could be specified when defining the constraint. (What would bloat our field definitions though, when we do that often).

larowlan’s picture

Issue tags: +Critical Office Hours

Should be able to guide any newcomers through this in today's office hours

larowlan’s picture

Fixes #4 #5 and #10 I think this is pretty close

dawehner’s picture

Great extraction of existing logic.

Now we have worked on moving code around, but nothing actually ensures that the critical is fixed: Validation is executed on an API / REST level,
the test still just deals with forms.

+++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldValueValidator.php
@@ -0,0 +1,43 @@
+    $value_taken = (bool) \Drupal::entityQuery($entity_type_id)

We still can't inject things? Too bad.

larowlan’s picture

added a test

rtbc'd the injections issue

getting close now

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Cool, thank you!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 2a55451 and pushed to 8.0.x. Thanks!

  • alexpott committed 2a55451 on 8.0.x
    Issue #2403817 by larowlan: Feed entity validation misses form...

Status: Fixed » Closed (fixed)

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

almaudoh’s picture