-
Notifications
You must be signed in to change notification settings - Fork 106
Allow to fetch custom meta fields for uploaded images. #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Nube2021
wants to merge
8
commits into
corcel:develop
Choose a base branch
from
Nube2021:image_custom_metafields
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6441c14
Allow to fetch custom meta fields for uploaded images.
Nube2021 261b99b
Update Image.php
Nube2021 62c9057
Update ContentFieldsTest.php
Nube2021 89abcdd
Update Image.php
Nube2021 09d379b
Correcting the name of the database file
Nube2021 5ad2a27
Uploading the correct database file
Nube2021 3de94a7
Fixing the database file
Nube2021 2bb09ee
deleted two lines from the method fillThumbnailFields I included by
Nube2021 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,11 @@ class Image extends BasicField implements FieldInterface | |
*/ | ||
protected $loadFromPost = false; | ||
|
||
/** | ||
* @var Post | ||
*/ | ||
protected $attachment; | ||
|
||
/** | ||
* @param string $field | ||
*/ | ||
|
@@ -87,6 +92,7 @@ protected function fillFields(Post $attachment) | |
$this->mime_type = $attachment->post_mime_type; | ||
$this->url = $attachment->guid; | ||
$this->description = $attachment->post_excerpt; | ||
$this->attachment = $attachment; | ||
} | ||
|
||
/** | ||
|
@@ -164,4 +170,28 @@ protected function fillMetadataFields(array $imageData) | |
$this->height = $imageData['height']; | ||
$this->sizes = $imageData['sizes']; | ||
} | ||
|
||
/** | ||
* @param string|array comma seperated string or an array | ||
* | ||
* @return string|array string if only one meta key was received as input, otherwise an array with the values of all meta keys received as input | ||
*/ | ||
public function fetchCustomMetadataValues($metaKeys) | ||
{ | ||
if (!is_array($metaKeys)) { | ||
$metaKeys = explode(',', $metaKeys); | ||
} | ||
|
||
$customMetaValues = []; | ||
|
||
foreach ($metaKeys as $metaKey) { | ||
$customMetaValues[] = $this->attachment->meta->{trim($metaKey)}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you check how many queries are you doing here? |
||
} | ||
|
||
if (count($customMetaValues) === 1) { | ||
return $customMetaValues[0]; | ||
} | ||
|
||
return $customMetaValues; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to create a
metadata
method passing or just 1 string or an array of metadata fields to be returned.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this
metadata
method should be another method, and then refactorfetchCustomMetadataValues()
one to accept both parameters.