/**
  * @param ResourceTransformer $transformer
  * @param RelationshipField $field
  * @param Context $context
  * @return Context
  */
 private function getInputChildContext(ResourceTransformer $transformer, RelationshipField $field, Context $context)
 {
     $childResourceDefinition = $field->getChildResource();
     // Check if we want to create a new child or edit an existing child
     if ($context->getAction() !== Action::CREATE && $field->canCreateNewChildren() && $this->hasInputIdentifier($transformer, $childResourceDefinition, $context, $input)) {
         $action = Action::EDIT;
     } else {
         $action = Action::CREATE;
     }
     $childContext = $context->getChildContext($field, $action);
     return $childContext;
 }
 /**
  * @param $resourceDefinition
  * @param $content
  * @param EntityFactoryContract $factory
  * @param ContextContract $context
  * @return array
  * @throws InvalidContextAction
  */
 public function entitiesFromIdentifiers($resourceDefinition, $content, EntityFactoryContract $factory, ContextContract $context)
 {
     $resourceDefinition = ResourceDefinitionLibrary::make($resourceDefinition);
     if (!Action::isWriteContext($context->getAction())) {
         throw InvalidContextAction::create('Writeable', $context->getAction());
     }
     $out = [];
     if (isset($content[self::RELATIONSHIP_ITEMS])) {
         // This is a list of items
         foreach ($content[self::RELATIONSHIP_ITEMS] as $item) {
             $entity = $this->fromIdentifier($resourceDefinition, $item, $factory, $context);
             if ($entity) {
                 $out[] = $entity;
             }
         }
     } else {
         $entity = $this->fromIdentifier($resourceDefinition, $content, $factory, $context);
         if ($entity) {
             $out[] = $entity;
         }
     }
     return $out;
 }
Beispiel #3
0
 /**
  * @param Context $context
  * @param CurrentPath $currentPath
  * @return bool
  */
 public function shouldInclude(Context $context, CurrentPath $currentPath)
 {
     $contextVisible = $context->shouldShowField($currentPath);
     if ($contextVisible !== null) {
         return $contextVisible && $this->isVisible($context->getAction());
     }
     return $this->hasAction($context->getAction());
 }