Skip to content
Permalink
Browse files

Restore description (and parts of title) option that got lost during …

…the last refactoring
  • Loading branch information...
flack committed Mar 10, 2019
1 parent 3a258b8 commit 3917d8547edcd3b9ffc11d813d4b0b284b77e81a
@@ -19,14 +19,23 @@ public function transform($input)
}
$result = ['objects' => []];
foreach ($input as $key => $value) {
if ($key === 'delete' || $key === 'description') {
if ($key === 'delete' || $key === 'description' || $key == 'title') {
$result[$key] = $value;
} else {
$result['objects'][$key] = parent::transform($value);
if ($key === 'file') {
$result['identifier'] = $result['objects'][$key]['identifier'];
}
if ($key === 'main') {
if (!empty($this->config['widget_config']['show_title'])) {
$result['title'] = $result['objects'][$key]['title'];
}
if (!empty($this->config['widget_config']['show_description'])) {
$result['description'] = $result['objects'][$key]['description'];
}
}
}
}
return $result;
@@ -52,6 +61,9 @@ public function reverseTransform($array)
if (!empty($this->config['widget_config']['show_description'])) {
$result['description'] = $array['description'];
}
if (!empty($this->config['widget_config']['show_title'])) {
$result['title'] = $array['title'];
}
return $result;
}
}
@@ -33,7 +33,8 @@ public function configureOptions(OptionsResolver $resolver)
helper::add_normalizers($resolver, [
'widget_config' => [
'map_action_elements' => false,
'show_title' => true
'show_title' => true,
'show_description' => false
],
'type_config' => [
'do_not_save_archival' => true,
@@ -64,6 +65,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)
if ($options['widget_config']['show_title']) {
$builder->add('title', TextType::class, ['required' => false]);
}
if ($options['widget_config']['show_description']) {
$builder->add('description', TextType::class, ['required' => false]);
}
$builder->add('delete', CheckboxType::class, ['attr' => [
"class" => "midcom_datamanager_photo_checkbox"
], "required" => false ]);
@@ -22,7 +22,8 @@ public function configureOptions(OptionsResolver $resolver)
helper::add_normalizers($resolver, [
'widget_config' => [
'map_action_elements' => false,
'show_title' => false
'show_title' => true,
'show_description' => false
],
'type_config' => [
'do_not_save_archival' => false,
@@ -41,18 +41,47 @@ public function save()
//delete?
}
if (!empty($this->value['delete'])) {
$this->map = [];
return $this->save_attachment_list();
}
$stat = true;
if (!empty($this->value['file'])) {
$this->value['file']->parentguid = $this->object->guid;
$existing = $this->load();
$filter = new imagefilter($this->config['type_config'], $this->save_archival);
$this->map = $filter->process($this->value['file'], $existing);
return $this->save_attachment_list();
$stat = $this->save_attachment_list();
}
if (!empty($this->value['delete'])) {
$this->map = [];
return $this->save_attachment_list();
if ( (array_key_exists('description', $this->value) || array_key_exists('title', $this->value))
&& $main = $this->get_main()) {
if (array_key_exists('description', $this->value)) {
$main->set_parameter('midcom.helper.datamanager2.type.blobs', 'description', $this->value['description']);
}
if (array_key_exists('title', $this->value) && $main->title != $this->value['title']) {
$main->title = $this->value['title'];
$main->update();
}
}
return $stat;
}
/**
* @return \midcom_db_attachment
*/
private function get_main()
{
if (!empty($this->map['main'])) {
return $this->map['main'];
}
$items = $this->load();
if (!empty($items['main'])) {
return $items['main'];
}
return true;
return false;
}
}
@@ -63,7 +63,6 @@ public function save()
{
$this->map = [];
$map = $this->load();
foreach ($this->value as $identifier => $images) {
if (!empty($images['file'])) {
if (is_numeric($identifier)) {
@@ -79,6 +78,16 @@ public function save()
$this->map[$identifier . $name . ':' . $image->guid] = $image;
}
}
if (!empty($images['main'])) {
if (array_key_exists('description', $images)) {
$images['main']->set_parameter('midcom.helper.datamanager2.type.blobs', 'description', $images['description']);
}
if (array_key_exists('title', $images) && $images['main']->title != $images['title']) {
$images['main']->title = $images['title'];
$images['main']->update();
}
}
}
return $this->save_image_map($map) && $this->save_attachment_list();
}
@@ -471,7 +471,7 @@ public function image_widget(FormView $view, array $data)
} else {
$size = 'unknown';
}
$string .= "<li title=\"{$info['guid']}\"><a href='{$info['url']}' target='_new'>{$size}:</a> {$info['formattedsize']}</li>";
$string .= "<li title=\"{$info['guid']}\">{$size}: <a href='{$info['url']}' target='_new'>{$info['formattedsize']}</a></li>";
}
$string .= '</ul>';
}
@@ -482,6 +482,10 @@ public function image_widget(FormView $view, array $data)
$view->children['title']->vars['attr']['placeholder'] = $this->renderer->humanize('title');
$string .= $this->renderer->widget($view->children['title']);
}
if (array_key_exists('description', $view->children)) {
$view->children['description']->vars['attr']['placeholder'] = $this->renderer->humanize('description');
$string .= $this->renderer->widget($view->children['description']);
}
$string .= '</td></tr></table></div>';
$string .= $this->renderer->row($data['form']['identifier']);
@@ -59,7 +59,7 @@ public function provider_transform()
return [
[null, []],
[['main' => $att], [
[['main' => $att, 'title' => 'test'], [
'objects' => [
'main' => [
'object' => $att,
@@ -81,7 +81,8 @@ public function provider_transform()
'identifier' => $att->guid,
'file' => null
]
]
],
'title' => 'test'
]]
];
}

0 comments on commit 3917d85

Please sign in to comment.
You can’t perform that action at this time.