Open WilsonParker opened 1 year ago
I changed the code below to
$key = str_replace($collection, '__media-custom-properties__.'.$collection, $requestAttribute);
// replace to
$key = '__media-custom-properties__.' . $collection;
original code is as below
namespace Ebess\AdvancedNovaMediaLibrary\Fields;
trait HandlesCustomPropertiesTrait
...
private function fillMediaCustomPropertiesFromRequest(
...
$key = str_replace($collection, '__media-custom-properties__.'.$collection, $requestAttribute);
}
Up on this issue. I can't make it worked eather. @ebess is it possible to fix this ?
@ebess : The problem is caused by overwriting $requestAttribute
in https://github.com/ebess/advanced-nova-media-library/blob/83b8410fe63b607dc7eda6b990cef33f971a6f9f/src/Fields/HandlesCustomPropertiesTrait.php#L85
Renaming the new variable to something like $targetRequestAttribute
should fix the problem.
Is there any solution to this issue?
@jan-tricks solution works for me ... could you fix this? thank you!
I have some issue with 5 custom fields (where saved only first).
if i print dump($requestAttribute);
in fillMediaCustomPropertiesFromRequest
then receive:
"__media-custom-properties__.images.0.alt"
"__media-custom-properties__.__media-custom-properties__.images.0.alt.0.url"
"__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.images.0.alt.0.url.0.adv_token"
"__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.images.0.alt.0.url.0.adv_token.0.date_from"
"__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.images.0.alt.0.url.0.adv_token.0.date_from.0.date_to"
my solution to put the $key = str_replace(...)
code before the foreach loop:
private function fillMediaCustomPropertiesFromRequest(NovaRequest $request, Media $media, int $index, string $collection, string $requestAttribute): void
{
// prevent overriding the custom properties set by other processes like generating conversions
$media->refresh();
// If we are dealing with nested resources or multiple panels, custom property fields are prefixed.
$key = str_replace($collection, '__media-custom-properties__.'.$collection, $requestAttribute);
/** @var Field $field */
foreach ($this->customPropertiesFields as $field) {
$targetAttribute = "custom_properties->{$field->attribute}";
$requestAttribute = "{$key}.{$index}.{$field->attribute}";
$field->fillInto($request, $media, $targetAttribute, $requestAttribute);
}
$media->save();
}
PS but the solution above (PR) should also work.
Hi @ebess, any plans fot the PR to be merged? Thanks
Hello @ebess, What are the plans for this to be merged. I was able to test this pull request locally https://github.com/ebess/advanced-nova-media-library/pull/425 and was successful. I went ahead and threw a approve on it as well but not sure if that means anything for you
I have some issue with 5 custom fields (where saved only first).
if i print
dump($requestAttribute);
infillMediaCustomPropertiesFromRequest
then receive:"__media-custom-properties__.images.0.alt" "__media-custom-properties__.__media-custom-properties__.images.0.alt.0.url" "__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.images.0.alt.0.url.0.adv_token" "__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.images.0.alt.0.url.0.adv_token.0.date_from" "__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.__media-custom-properties__.images.0.alt.0.url.0.adv_token.0.date_from.0.date_to"
my solution to put the
$key = str_replace(...)
code before the foreach loop:private function fillMediaCustomPropertiesFromRequest(NovaRequest $request, Media $media, int $index, string $collection, string $requestAttribute): void { // prevent overriding the custom properties set by other processes like generating conversions $media->refresh(); // If we are dealing with nested resources or multiple panels, custom property fields are prefixed. $key = str_replace($collection, '__media-custom-properties__.'.$collection, $requestAttribute); /** @var Field $field */ foreach ($this->customPropertiesFields as $field) { $targetAttribute = "custom_properties->{$field->attribute}"; $requestAttribute = "{$key}.{$index}.{$field->attribute}"; $field->fillInto($request, $media, $targetAttribute, $requestAttribute); } $media->save(); }
PS but the solution above (PR) should also work.
Thank you!! It works for me!!!
I use 4.1.6 version When the code is as below, only 'a' is updated
Images::make('Images', 'gallery') ->customPropertiesFields([ Text::make('a'), Text::make('b'), ])