Allow to fetch custom meta fields for uploaded images.#22
Open
Nube2021 wants to merge 8 commits intocorcel:developfrom
Open
Allow to fetch custom meta fields for uploaded images.#22Nube2021 wants to merge 8 commits intocorcel:developfrom
Nube2021 wants to merge 8 commits intocorcel:developfrom
Conversation
Some Wordpress plugins allow the user in the backend to add some extra
meta information to an image. For instance, the plugin „WP Gallery
Custom Links“ allows to add a custom url, a css class and other
information to an image. This commit adds a function to the Image Field
class with which it is possible to fetch these custom meta fields. The
function is called „fetchCustomMetaValues“ and receives as input a comma
separated list or an array with the meta keys names that should be
fetched.
Testing was included with the function „testImageCustomMetadataValues“
in ContentFieldsTest.php. The database was updated and includes now
images with some extra meta fields. Here are the results of the tests:
$ ./vendor/bin/phpunit --filter
{ContentFieldsTest::testImageCustomMetadataValues}
PHPUnit 4.2.2 by Sebastian Bergmann.
Configuration read from ……/phpunit.xml
.
Time: 167 ms, Memory: 6.00MB
OK (1 test, 6 assertions)
jgrossi
reviewed
Mar 9, 2017
| $customMetaValues = []; | ||
|
|
||
| foreach ($metaKeys as $metaKey) { | ||
| $customMetaValues[] = $this->attachment->meta->{trim($metaKey)}; |
Member
There was a problem hiding this comment.
Did you check how many queries are you doing here?
| * | ||
| * @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) |
Member
There was a problem hiding this comment.
Maybe it would be better to create a metadata method passing or just 1 string or an array of metadata fields to be returned.
Member
There was a problem hiding this comment.
Maybe this metadata method should be another method, and then refactor fetchCustomMetadataValues() one to accept both parameters.
src/Field/Image.php
Outdated
| $size->mime_type = $data['mime-type']; | ||
|
|
||
| $imgDir = substr($this->url, 0, strrpos($this->url, '/')); | ||
| $size->url = $imgDir.'/'.$data['file']; |
Member
There was a problem hiding this comment.
This is not being tested. If you can please write a test. I guess no fields are being tested, so if you can please test all of them.
Author
There was a problem hiding this comment.
These two lines weren't intended to be included. I included them by mistake. I have already removed them.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Some Wordpress plugins allow the user in the backend to add some extra
meta information to an image. For instance, the plugin „WP Gallery
Custom Links“ allows to add a custom url, a css class and other
information to an image. This commit adds a function to the Image Field
class with which it is possible to fetch these custom meta fields. The
function is called „fetchCustomMetaValues“ and receives as input a comma
separated list or an array with the meta keys names that should be
fetched.
Testing was included with the function „testImageCustomMetadataValues“
in ContentFieldsTest.php. The database was updated and includes now
images with some extra meta fields. Here are the results of the tests:
$ ./vendor/bin/phpunit --filter
{ContentFieldsTest::testImageCustomMetadataValues}
PHPUnit 4.2.2 by Sebastian Bergmann.
Configuration read from ……/phpunit.xml
.
Time: 167 ms, Memory: 6.00MB
OK (1 test, 6 assertions)