Skip to content

Commit

Permalink
[BUGFIX] meta.yaml file will now be created for an already uploaded m…
Browse files Browse the repository at this point in the history
…edia file that did not have an associated meta.yaml file before --> v1.0.1
  • Loading branch information
clivebeckett committed Apr 10, 2020
1 parent 7c9cbdc commit aa7a5cb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.0.1
## 10-04-2020

1. [](#bugfix)
* meta.yaml file will now be created for an already uploaded media file that did not have an associated meta.yaml file before

# v1.0.0
## 20-03-2020

Expand Down
39 changes: 27 additions & 12 deletions admin-addon-media-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,38 @@ public function editMetaDataFile($e)
} else {
$metaDataFilePath = $filePath . '.meta.yaml';

/**
* get array of all current metadata for the file
* this is to avoid overwriting data that has been added to the meta.yaml file in the file browser
*/
$storedMetaData = Yaml::parse(file_get_contents($metaDataFilePath));

/**
* get the list of form data from the fields configuration
*/
$arrMetaKeys = $this->editableFields();

/**
* overwrite the currently stored data for each field in the form
*/
foreach ($arrMetaKeys as $metaKey => $info) {
if (isset($_POST[$metaKey])) {
$storedMetaData[$metaKey] = $_POST[$metaKey];
if (file_exists($metaDataFilePath)) {
/**
* get array of all current metadata for the file
* this is to avoid overwriting data that has been added to the meta.yaml file in the file browser
*/
$storedMetaData = Yaml::parse(file_get_contents($metaDataFilePath));

/**
* overwrite the currently stored data for each field in the form
*/
foreach ($arrMetaKeys as $metaKey => $info) {
if (isset($_POST[$metaKey])) {
$storedMetaData[$metaKey] = $_POST[$metaKey];
}
}

} else {
/**
* create metaData in case the meta data file does not yet exist
*/
$storedMetaData = [];
foreach ($arrMetaKeys as $metaKey => $info) {
if (isset($_POST[$metaKey])) {
$storedMetaData[$metaKey] = $_POST[$metaKey];
} else {
$storedMetaData[$metaKey] = '';
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Admin Addon Media Metadata
version: 1.0.0
version: 1.0.1
description: 'This plugin is an addon for the Grav CMS Admin plugin and lets you add and edit metadata for media files'
icon: plug
author:
Expand All @@ -12,7 +12,8 @@ docs: https://github.com/clivebeckett/grav-plugin-admin-addon-media-metadata/blo
license: MIT

dependencies:
- { name: grav, version: '>=1.6.0' }
- { name: grav, version: '1.5 - 1.6' }
- { name: admin, version: '1.8 - 1.9' }

form:
validation: loose
Expand Down

0 comments on commit aa7a5cb

Please sign in to comment.