public function __construct(EntityTypeInterface $entity_type, $command_class) { parent::__construct($command_class); $this->entity_type = $entity_type; $this->command_state['embedded_entity_type'] = $entity_type->getPrefix(); $this->command_state['embedded_entity_commands'] = new EmbeddedEntityTypeCommandList(); }
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 getWhitelistedAttributes(EntityTypeInterface $entity_type) { $root_prefix = $entity_type->getRoot()->getPrefix(); $path_prefix = preg_quote(preg_replace("#^{$root_prefix}\\.?#", '', $entity_type->getScopeKey())); $attribute_whitelist = []; foreach ($this->getParameter('attribute_whitelist', []) as $attribute_name) { preg_match("#^{$path_prefix}\\.?(?<name>[a-z_]+)\$#", $attribute_name, $match); if (isset($match['name'])) { $attribute_whitelist[] = $match['name']; } } return array_unique($attribute_whitelist); }
/** * Returns the scheme that is used for access of the temporary file/asset storage for * the given aggregate root type. When no type is given the default scheme name * for the common temporary file/asset storage is returned ("tempfiles"). * * @param EntityTypeInterface $entity_type aggregate root type instance * * @return string scheme name, e.g. 'tempfiles' or 'usertempfiles' */ public function getTempScheme(EntityTypeInterface $entity_type = null) { if (null === $entity_type) { return self::SCHEME_TEMPFILES; } return $entity_type->getPrefix() . '.' . self::SCHEME_TEMPFILES; }
protected function getLabelFieldname(EntityTypeInterface $embedded_type) { $type_prefix = $embedded_type->getPrefix(); $label_field_option = $type_prefix . '.label_attribute'; if ($this->hasOption($label_field_option)) { $label_fieldname = $this->getOption($label_field_option); if (!$embedded_type->hasAttribute($label_fieldname)) { throw new RuntimeError(sprintf('Non-existant label_attribute "%s" configured for embed-reference-type: %s', $label_fieldname, $embedded_type->getName())); } return $label_fieldname; } return null; }