In general + for #1743686: Condition Plugin System we'll need choice based validation, i.e. validate whether the value is one of the allowed ones. Symfony has a constraint for that. In my test it triggered a deprecated warning, what I think is a symfony bug though.

Also, for validating multiple-valued typed data objects (=lists) we'll need to fix our current validator integration as right now lists are not un-wrapped and the constraint validator dies when receiving the array-access object containing typed objects. To solve that I'd suggest adding an isComplexData() helper function to typed data and make it return TRUE for lists containing complex data and FALSE for lists containing simple data. Then we unwrap simple data only and have validation work.

Related:
#1913328: Provide general list and map classes
#1758622: Provide the options list of an entity field - once we've done that we can leverage it for validation.

CommentFileSizeAuthor
#3 d8_choice.patch2.38 KBfago
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago’s picture

Issue tags: +typed data

Also tagging as typed-data.

fago’s picture

Here is my start - without the typed data fixes or fixing the choice validator using a deprecated method.

Usage would be like that:

 *     "bundles" = {
 *       "type" = "string",
 *       "list" = true,
 *       "constraints" = {
 *         "Choice" = {
 *           "multiple" = true,
 *           "callback" = {
 *             "Drupal\node\Plugin\Core\Condition\NodeType",
 *             "validBundles"
 *           }
 *         }
 *       }
 *     }
 *   }
 * )
 */
class NodeType extends ConditionPluginBase {

  /**
   * Callback for the bundle context constraint.
   */
  public static function validBundles() {
    return array_keys(node_type_get_types());
  }

Once we've typed data options-list as callback we might want to default to this one.

fago’s picture

Status: Active » Needs work
FileSize
2.38 KB

Forgot to post interim work.

fago’s picture

Issue summary: View changes

Updated issue summary.

fago’s picture

Issue summary: View changes
Status: Needs work » Closed (works as designed)

Meanwhile we've allowed values validation based on typed data already.