diff --git a/application/data/doctrine-proxies/__CG__OmekaEntityResourceTemplate.php b/application/data/doctrine-proxies/__CG__OmekaEntityResourceTemplate.php index 4c55668484..9d30111684 100644 --- a/application/data/doctrine-proxies/__CG__OmekaEntityResourceTemplate.php +++ b/application/data/doctrine-proxies/__CG__OmekaEntityResourceTemplate.php @@ -66,10 +66,10 @@ public function __construct(?\Closure $initializer = null, ?\Closure $cloner = n public function __sleep() { if ($this->__isInitialized__) { - return ['__isInitialized__', 'id', 'label', 'owner', 'resourceClass', 'titleProperty', 'descriptionProperty', 'resourceTemplateProperties', 'resources']; + return ['__isInitialized__', 'id', 'label', 'owner', 'resourceClass', 'titleProperty', 'descriptionProperty', 'settings', 'resourceTemplateProperties', 'resources']; } - return ['__isInitialized__', 'id', 'label', 'owner', 'resourceClass', 'titleProperty', 'descriptionProperty', 'resourceTemplateProperties', 'resources']; + return ['__isInitialized__', 'id', 'label', 'owner', 'resourceClass', 'titleProperty', 'descriptionProperty', 'settings', 'resourceTemplateProperties', 'resources']; } /** @@ -301,6 +301,28 @@ public function getDescriptionProperty() return parent::getDescriptionProperty(); } + /** + * {@inheritDoc} + */ + public function setSettings(array $settings) + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'setSettings', [$settings]); + + return parent::setSettings($settings); + } + + /** + * {@inheritDoc} + */ + public function getSettings() + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'getSettings', []); + + return parent::getSettings(); + } + /** * {@inheritDoc} */ diff --git a/application/data/install/schema.sql b/application/data/install/schema.sql index 58c9dac0b3..59d6cd6201 100644 --- a/application/data/install/schema.sql +++ b/application/data/install/schema.sql @@ -176,6 +176,7 @@ CREATE TABLE `resource_template` ( `title_property_id` int(11) DEFAULT NULL, `description_property_id` int(11) DEFAULT NULL, `label` varchar(190) COLLATE utf8mb4_unicode_ci NOT NULL, + `settings` longtext COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '(DC2Type:json_array)', PRIMARY KEY (`id`), UNIQUE KEY `UNIQ_39ECD52EEA750E8` (`label`), KEY `IDX_39ECD52E7E3C61F9` (`owner_id`), diff --git a/application/data/migrations/20200824000000_AddResourceTemplateSettings.php b/application/data/migrations/20200824000000_AddResourceTemplateSettings.php new file mode 100644 index 0000000000..367717137b --- /dev/null +++ b/application/data/migrations/20200824000000_AddResourceTemplateSettings.php @@ -0,0 +1,23 @@ +exec($sql); + + $sql = <<exec($sql); + } +} diff --git a/application/src/Api/Adapter/ResourceTemplateAdapter.php b/application/src/Api/Adapter/ResourceTemplateAdapter.php index afa179e7e0..7c6c54402d 100644 --- a/application/src/Api/Adapter/ResourceTemplateAdapter.php +++ b/application/src/Api/Adapter/ResourceTemplateAdapter.php @@ -147,6 +147,11 @@ public function hydrate(Request $request, EntityInterface $entity, $entity->setDescriptionProperty($descriptionProperty); } + if ($this->shouldHydrate($request, 'o:settings')) { + $settings = $request->getValue('o:settings') ?: []; + $entity->setSettings($settings); + } + if ($this->shouldHydrate($request, 'o:resource_template_property') && isset($data['o:resource_template_property']) && is_array($data['o:resource_template_property']) diff --git a/application/src/Api/Representation/ResourceTemplateRepresentation.php b/application/src/Api/Representation/ResourceTemplateRepresentation.php index 9fba29cc39..eb211b6dea 100644 --- a/application/src/Api/Representation/ResourceTemplateRepresentation.php +++ b/application/src/Api/Representation/ResourceTemplateRepresentation.php @@ -37,6 +37,7 @@ public function getJsonLd() 'o:resource_class' => $resourceClass, 'o:title_property' => $titleProperty, 'o:description_property' => $descriptionProperty, + 'o:settings' => $this->settings(), 'o:resource_template_property' => $this->resourceTemplateProperties(), ]; } @@ -95,6 +96,27 @@ public function descriptionProperty() ->getRepresentation($this->resource->getDescriptionProperty()); } + /** + * @return array + */ + public function settings() + { + return $this->resource->getSettings(); + } + + /** + * @param string $name + * @param mixed $default + * @return mixed + */ + public function setting($name, $default = null) + { + $settings = $this->resource->getSettings(); + return array_key_exists($name, $settings) + ? $settings[$name] + : $default; + } + /** * Return the properties assigned to this resource template. * diff --git a/application/src/Entity/ResourceTemplate.php b/application/src/Entity/ResourceTemplate.php index 872953cc6d..0a5948027d 100644 --- a/application/src/Entity/ResourceTemplate.php +++ b/application/src/Entity/ResourceTemplate.php @@ -44,6 +44,11 @@ class ResourceTemplate extends AbstractEntity */ protected $descriptionProperty; + /** + * @Column(type="json_array", nullable=false) + */ + protected $settings; + /** * @OneToMany( * targetEntity="ResourceTemplateProperty", @@ -124,6 +129,16 @@ public function getDescriptionProperty() return $this->descriptionProperty; } + public function setSettings(array $settings) + { + $this->settings = $settings; + } + + public function getSettings() + { + return $this->settings; + } + public function getResourceTemplateProperties() { return $this->resourceTemplateProperties;