Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 9 |
BundleConstraint | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 9 |
getBundleOption | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 5 |
|||
getDefaultOption | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
getRequiredOptions | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraint. | |
*/ | |
namespace Drupal\Core\Entity\Plugin\Validation\Constraint; | |
use Symfony\Component\Validator\Constraint; | |
/** | |
* Checks if a value is a valid entity type. | |
* | |
* @Constraint( | |
* id = "Bundle", | |
* label = @Translation("Bundle", context = "Validation"), | |
* type = { "entity", "entity_reference" } | |
* ) | |
*/ | |
class BundleConstraint extends Constraint { | |
/** | |
* The default violation message. | |
* | |
* @var string | |
*/ | |
public $message = 'The entity must be of bundle %bundle.'; | |
/** | |
* The bundle option. | |
* | |
* @var string|array | |
*/ | |
public $bundle; | |
/** | |
* Gets the bundle option as array. | |
* | |
* @return array | |
*/ | |
public function getBundleOption() { | |
// Support passing the bundle as string, but force it to be an array. | |
if (!is_array($this->bundle)) { | |
$this->bundle = array($this->bundle); | |
} | |
return $this->bundle; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getDefaultOption() { | |
return 'bundle'; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getRequiredOptions() { | |
return array('bundle'); | |
} | |
} |