Skip to content

Commit

Permalink
Fix missing required marks on fields, make thumbnail not required
Browse files Browse the repository at this point in the history
Fixes cause of #146
  • Loading branch information
bojidar-bg committed May 27, 2018
1 parent 4ea2831 commit 4a1f67c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/routes/asset.php
Expand Up @@ -201,6 +201,8 @@
$matches = [];
if (preg_match('|youtube.com/watch\\?v=([^&]+)|', $previews[$i]['link'], $matches)) {
$previews[$i]['thumbnail'] = 'http://img.youtube.com/vi/'.$matches[1].'/default.jpg';
} else {
$previews[$i]['thumbnail'] = $previews[$i]['link'];
}
} else {
$previews[$i]['thumbnail'] = $previews[$i]['link'];
Expand Down
6 changes: 3 additions & 3 deletions src/routes/asset_edit.php
Expand Up @@ -262,12 +262,12 @@ function _add_previews_to_edit($c, $error, &$response, $edit_id, $previews, $ass
$query->bindValue(':edit_id', (int) $edit_id, PDO::PARAM_INT);

foreach ($c->constants['asset_edit_preview_fields'] as $i => $field) {
if (!$required) {
if (!$required || $field == 'thumbnail') { // thumb is not required
if (isset($preview[$field]) && !(isset($original_preview) && $original_preview[$field] == $preview[$field])) {
$has_changes = true;
$query->bindValue(':' . $field, $preview[$field]);
} elseif (!isset($preview[$field]) && !isset($original_preview)) {
$query->bindValue(':' . $field, $preview[$field]);
} elseif (!isset($original_preview)) {
$query->bindValue(':' . $field, '');
} else {
$query->bindValue(':' . $field, null, PDO::PARAM_NULL);
}
Expand Down
8 changes: 4 additions & 4 deletions templates/_asset_fields.phtml
Expand Up @@ -148,7 +148,7 @@ $_asset_values = array_merge([
<div class="form-group">
<label class="col-md-4 control-label required_mark" for="description">Description</label>
<div class="col-md-5">
<textarea class="form-control" id="description" name="description" rows="7"><?php echo esc($_asset_values['description']) ?></textarea>
<textarea class="form-control" id="description" name="description" required="" rows="7"><?php echo esc($_asset_values['description']) ?></textarea>
<span class="help-block">The description which would be visible on the asset page</span>
</div>
</div>
Expand Down Expand Up @@ -179,7 +179,7 @@ $_asset_values = array_merge([
<input type="hidden" name="previews[<?php echo $i ?>][enabled]" value="true">
<label>
<input type="checkbox" name="previews[<?php echo $i ?>][remove]" value="true">
Cancel edit
Remove
</label>

<?php } else { // From base asset ?>
Expand All @@ -201,7 +201,7 @@ $_asset_values = array_merge([
<?php } else { ?>
<input type="hidden" name="previews[<?php echo $i ?>][operation]" value="insert">
<label>
<input type="checkbox" name="previews[<?php echo $i ?>][enabled]" value="true">
<input type="checkbox" name="previews[<?php echo $i ?>][enabled]" value="true" onchange="document.getElementById('previews[<?php echo $i ?>][link]').required = this.checked;">
Enable
</label>
<?php } ?>
Expand Down Expand Up @@ -231,7 +231,7 @@ $_asset_values = array_merge([
</div>

<div class="form-group">
<label class="col-md-4 control-label required_mark" for="previews[<?php echo $i ?>][thumbnail]">Link to thumbnail (To be removed)</label>
<label class="col-md-4 control-label" for="previews[<?php echo $i ?>][thumbnail]">Link to thumbnail</label>
<div class="col-md-5">
<input id="previews[<?php echo $i ?>][thumbnail]" name="previews[<?php echo $i ?>][thumbnail]" type="text" placeholder="Image Link" class="form-control input-md" value="<?php echo esc($preview['thumbnail']) ?>">
</div>
Expand Down

0 comments on commit 4a1f67c

Please sign in to comment.