/**
  * Used f.e. to generate a human-readable role definition: substitute entity ids with their identifiers/names
  *
  * @param Limitation $limitation
  * @return array keys: identifier, values
  */
 public function getLimitationArrayWithIdentifiers(Limitation $limitation)
 {
     $retValues = array();
     $values = $limitation->limitationValues;
     switch ($limitation->getIdentifier()) {
         case 'Section':
         case 'NewSection':
             foreach ($values as $value) {
                 $section = $this->sectionMatcher->matchOneByKey($value);
                 $retValues[] = $section->identifier;
             }
             break;
         case 'SiteAccess':
             foreach ($values as $value) {
                 $name = "No/unknown SiteAccess Found";
                 if (array_key_exists($value, $this->siteAccessList)) {
                     $name = $this->siteAccessList[$value];
                 }
                 $retValues[] = $name;
             }
             break;
         case 'ParentClass':
         case 'Class':
             foreach ($values as $value) {
                 $contentType = $this->contentTypeMatcher->matchOneByKey($value);
                 $retValues[] = $contentType->identifier;
             }
             break;
         default:
             $retValues = $values;
     }
     return array('identifier' => $limitation->getIdentifier(), 'values' => $retValues);
 }
 public function mapLimitationForm(FormInterface $form, Limitation $data)
 {
     $options = $this->getChoiceFieldOptions() + ['multiple' => true, 'label' => $data->getIdentifier(), 'required' => false];
     $choices = $this->getSelectionChoices();
     asort($choices, SORT_NATURAL | SORT_FLAG_CASE);
     $options += ['choices' => $choices];
     $form->add('limitationValues', 'choice', $options);
 }
 /**
  * Validates single Limitation.
  *
  * @throws \eZ\Publish\Core\Base\Exceptions\BadStateException If the Role settings is in a bad state
  *
  * @param \eZ\Publish\API\Repository\Values\User\Limitation $limitation
  *
  * @return \eZ\Publish\Core\FieldType\ValidationError[]
  */
 public function validateLimitation(Limitation $limitation)
 {
     $identifier = $limitation->getIdentifier();
     if (!isset($this->settings['limitationTypes'][$identifier])) {
         throw new BadStateException('$identifier', "limitationType[{$identifier}] is not configured");
     }
     /**
      * @var \eZ\Publish\SPI\Limitation\Type
      */
     $type = $this->settings['limitationTypes'][$identifier];
     // This will throw if it does not pass
     $type->acceptValue($limitation);
     // This return array of validation errors
     return $type->validate($limitation);
 }
 /**
  * Create new Blocking Limitation with identifier injected dynamically
  *
  * @throws \InvalidArgumentException If $identifier is empty
  * @param string $identifier The identifier of the limitation
  * @param array $limitationValues
  */
 public function __construct($identifier, array $limitationValues)
 {
     if (empty($identifier)) {
         throw new \InvalidArgumentException('Argument $identifier can not be empty');
     }
     parent::__construct(array('identifier' => $identifier, 'limitationValues' => $limitationValues));
 }
 /**
  * Tests that the resulting policy contains the identifier
  *
  * @param \eZ\Publish\API\Repository\Values\User\Limitation $result
  *
  * @depends testParse
  */
 public function testResultContainsIdentifier($result)
 {
     $this->assertEquals('Class', $result->getIdentifier());
 }
 /**
  * Adds a limitation with the given identifier and list of values.
  *
  * @param \eZ\Publish\API\Repository\Values\User\Limitation $limitation
  */
 public function addLimitation(Limitation $limitation)
 {
     $limitationIdentifier = $limitation->getIdentifier();
     $this->limitations[$limitationIdentifier] = $limitation;
 }
 /**
  * Visits a limitation
  *
  * @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
  * @param \eZ\Publish\API\Repository\Values\User\Limitation $limitation
  */
 protected function visitLimitation(Generator $generator, Limitation $limitation)
 {
     $generator->startHashElement('limitation');
     $generator->startAttribute('identifier', $limitation->getIdentifier());
     $generator->endAttribute('identifier');
     $generator->startHashElement('values');
     $generator->startList('ref');
     foreach ($limitation->limitationValues as $limitationValue) {
         $generator->startObjectElement('ref');
         $generator->startAttribute('href', $limitationValue);
         $generator->endAttribute('href');
         $generator->endObjectElement('ref');
     }
     $generator->endList('ref');
     $generator->endHashElement('values');
     $generator->endHashElement('limitation');
 }
 public function mapLimitationForm(FormInterface $form, Limitation $data)
 {
     $form->add($form->getConfig()->getFormFactory()->createBuilder()->create('limitationValues', HiddenType::class, ['required' => false, 'label' => $data->getIdentifier()])->addModelTransformer(new UDWBasedValueTransformer())->setAutoInitialize(false)->getForm());
 }