Commit 97b863d5 authored by ephoto_dam's avatar ephoto_dam

Add Ephoto Dam Field Constraint

parent 164b14d1
......@@ -17,7 +17,8 @@ use Drupal\Core\TypedData\TraversableTypedDataInterface;
* description = @Translation("Stores a Ephoto Dam URL and then outputs some embed code"),
* category = @Translation("Media"),
* default_widget = "ephoto_dam_field_widget",
* default_formatter = "ephoto_dam_field_formatter"
* default_formatter = "ephoto_dam_field_formatter",
* constraints = {"EphotoDamFieldValidation" = {}}
* )
*/
class EphotoDamField extends FieldItemBase {
......@@ -64,15 +65,12 @@ class EphotoDamField extends FieldItemBase {
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['url'] = DataDefinition::create('string')
->setLabel(t('Url'));
//->setRequired(true);
$properties['image_size'] = DataDefinition::create('string')
->setLabel(t('Image size'));
//->setRequired(true);
$properties['version'] = DataDefinition::create('string')
->setLabel(t('Version'));
//->setRequired(true);
return $properties;
}
......
<?php
namespace Drupal\ephoto_dam_field\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
/**
* Validation constraint for the ephoto dam field.
*
* @Constraint(
* id = "EphotoDamFieldValidation"
* )
*/
class EphotoDamFieldConstraint extends Constraint {
}
<?php
namespace Drupal\ephoto_dam_field\Plugin\Validation\Constraint;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Validates the Ephoto Dam Field
*/
class EphotoDamFieldConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
/**
* Create an instance of the validator.
*/
public function __construct() {
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static();
}
/**
* {@inheritdoc}
*/
public function validate($field, Constraint $constraint) {
if (!isset($field->image_size)) {
return NULL;
}
error_log(var_export($field->image_size, true));
//$this->context->addViolation('');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment