Skip to content

Commit

Permalink
Added a batch edit option to set the media language.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Oct 22, 2017
1 parent 648535f commit bd3cce3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 28 deletions.
12 changes: 12 additions & 0 deletions application/src/Api/Adapter/MediaAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,16 @@ public function hydrateOwner(Request $request, EntityInterface $entity)
$entity->setOwner($entity->getItem()->getOwner());
}
}

public function preprocessBatchUpdate(array $data, Request $request)
{
$rawData = $request->getContent();
$data = parent::preprocessBatchUpdate($data, $request);

if (array_key_exists('o:lang', $rawData)) {
$data['o:lang'] = $rawData['o:lang'];
}

return $data;
}
}
84 changes: 57 additions & 27 deletions application/src/Form/ResourceBatchUpdateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,34 +91,57 @@ public function init()
],
]);

if ($resourceType === 'item') {
$this->add([
'name' => 'add_to_item_set',
'type' => ItemSetSelect::class,
'attributes' => [
'id' => 'add-to-item-sets',
'class' => 'chosen-select',
'multiple' => true,
'data-placeholder' => 'Select item sets', // @translate
],
'options' => [
'label' => 'Add to item sets', // @translate
],
]);
switch ($resourceType) {
case 'item':
$this->add([
'name' => 'add_to_item_set',
'type' => ItemSetSelect::class,
'attributes' => [
'id' => 'add-to-item-sets',
'class' => 'chosen-select',
'multiple' => true,
'data-placeholder' => 'Select item sets', // @translate
],
'options' => [
'label' => 'Add to item sets', // @translate
],
]);

$this->add([
'name' => 'remove_from_item_set',
'type' => ItemSetSelect::class,
'attributes' => [
'id' => 'remove-from-item-sets',
'class' => 'chosen-select',
'multiple' => true,
'data-placeholder' => 'Select item sets', // @translate
],
'options' => [
'label' => 'Remove from item sets', // @translate
],
]);
$this->add([
'name' => 'remove_from_item_set',
'type' => ItemSetSelect::class,
'attributes' => [
'id' => 'remove-from-item-sets',
'class' => 'chosen-select',
'multiple' => true,
'data-placeholder' => 'Select item sets', // @translate
],
'options' => [
'label' => 'Remove from item sets', // @translate
],
]);
break;

case 'media':
$this->add([
'name' => 'clear_language',
'type' => 'Checkbox',
'options' => [
'label' => 'Clear language', // @transalte
],
]);

$this->add([
'name' => 'language',
'type' => 'Text',
'attributes' => [
'class' => 'value-language active',
],
'options' => [
'label' => 'Set language', // @transalte
],
]);
break;
}

$this->add([
Expand Down Expand Up @@ -247,6 +270,12 @@ public function preprocessData()
if (isset($data['clear_property_values'])) {
$dataRemove['clear_property_values'] = $data['clear_property_values'];
}
if (!empty($data['clear_language'])) {
$dataRemove['o:lang'] = null;
}
if (!empty($data['language'])) {
$dataRemove['o:lang'] = $data['language'];
}

// Set the data to append.
if (!empty($data['value'])) {
Expand Down Expand Up @@ -278,6 +307,7 @@ public function preprocessData()
$processeds = [
'csrf', 'is_public', 'is_open', 'resource_template', 'resource_class',
'remove_from_item_set', 'add_to_item_set', 'clear_property_values',
'clear_language', 'language',
'value', 'id', 'o:id',
];
foreach ($data as $key => $value) {
Expand Down
4 changes: 3 additions & 1 deletion application/view/omeka/admin/media/batch-edit.phtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
$form->prepare();
$this->htmlElement('body')->appendAttribute('class', 'batch-edit media');
$escape = $this->plugin('escapeHtml');
$this->headStyle()->appendStyle('.inputs input.value-language.active[type="text"] { background-color: #fff; padding: 0 5px; display: inherit; }');
$this->headScript()->appendFile($this->assetUrl('js/resource-form.js', 'Omeka'));
$form->prepare();
?>
<?php echo $this->pageTitle($this->translate('Batch edit medias')); ?>

Expand Down

0 comments on commit bd3cce3

Please sign in to comment.