Exemplo n.º 1
0
 protected function moveTempFilesToFinalLocation(HasEmbeddedEntityEventsInterface $event, EntityTypeInterface $entity_type)
 {
     foreach ($event->getData() as $attr_name => $attr_data) {
         $attribute = $entity_type->getAttribute($attr_name);
         $art = $attribute->getRootType();
         if ($attribute instanceof HandlesFileListInterface) {
             $property_name = $attribute->getFileLocationPropertyName();
             foreach ($attr_data as $file) {
                 $this->moveTempFileToFinalLocation($file[$property_name], $art);
             }
         } elseif ($attribute instanceof HandlesFileInterface) {
             $this->moveTempFileToFinalLocation($attr_data[$attribute->getFileLocationPropertyName()], $art);
         }
     }
     // there may be embedded entity events that have files on their attributes as well => recurse into them
     foreach ($event->getEmbeddedEntityEvents() as $embedded_event) {
         $attr_name = $embedded_event->getParentAttributeName();
         $embedded_entity_type = $embedded_event->getEmbeddedEntityType();
         $embedded_attribute = $entity_type->getAttribute($attr_name);
         $embedded_type = $embedded_attribute->getEmbeddedTypeByPrefix($embedded_entity_type);
         $this->moveTempFilesToFinalLocation($embedded_event, $embedded_type);
     }
 }
 protected function fetchDisplayFields(EntityTypeInterface $embedded_type)
 {
     $resource = $this->getPayload('resource');
     $resource_type = $resource->getType()->getRoot();
     $resource_type_prefix = $resource_type->getPrefix();
     $embedded_type_prefix = $embedded_type->getPrefix();
     $scope = $this->getOption('view_scope', 'default.resource');
     $template_name = sprintf('%s.%s.%s', $resource_type_prefix, $this->attribute->getPath(), $embedded_type_prefix);
     $view_template = $this->view_template_service->getViewTemplate($scope, $template_name, $this->output_format);
     $display_fields = [];
     foreach ($view_template->extractAllFields() as $field) {
         if ($embedded_type->hasAttribute($field->getName())) {
             $attribute = $embedded_type->getAttribute($field->getName());
             if ($attribute->getOption('mirrored', false)) {
                 $display_fields[] = $attribute->getName();
             }
         }
     }
     return $display_fields;
 }