Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions src/FieldDescription/BaseFieldDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,29 @@
* Some options are global across the different contexts, other are
* context specifics.
*
* Global options :
* Global options:
* - type (m): define the field type (use to tweak the form or the list)
* - template (o) : the template used to render the field
* - name (o) : the name used (label in the form, title in the list)
* - link_parameters (o) : add link parameter to the related Admin class when
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently link_parameters it us used in the route generator, so I guess is kind of global:

$parameters = array_merge($parameters, $admin->getParentFieldDescription()->getOption('link_parameters', []));

* - template (o): the template used to render the field
* - label (o): the name used (label in the form, title in the list)
* - accessor (o): the method or the property path to retrieve the related value
* - associated_property (o): the method or the property path to retrieve the "string"
* representation of the collection element.
* - link_parameters (o): add link parameter to the related Admin class when
* the Admin.generateUrl is called
* - accessor : the method or the property path to retrieve the related value
* - associated_tostring : (deprecated, use associated_property option)
* the method to retrieve the "string" representation
* of the collection element.
* - associated_property : property path to retrieve the "string" representation
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

associated_property it is used in RenderElementExtension which means it is used in render_relation_element Twig filter that it is used globally: https://github.com/sonata-project/SonataAdminBundle/search?q=render_relation_element

* of the collection element.
*
* Form Field options :
* Form Field options:
* - field_type (o): the widget class to use to render the field
* - field_options (o): the options to give to the widget
* - edit (o) : list|inline|standard (only used for associated admin)
* - list : open a popup where the user can search, filter and click on one field
* - edit (o): list|inline|standard (only used for associated admin)
* - list: open a popup where the user can search, filter and click on one field
* to select one item
* - inline : the associated form admin is embedded into the current form
* - standard : the associated admin is created through a popup
* - inline: the associated form admin is embedded into the current form
* - standard: the associated admin is created through a popup
*
* List Field options :
* List Field options:
* - identifier (o): if set to true a link appear on to edit the element
*
* Filter Field options :
* - options (o): options given to the Filter object
* Filter Field options:
* - field_type (o): the widget class to use to render the field
* - field_options (o): the options to give to the widget
*
Expand Down Expand Up @@ -269,11 +265,12 @@ public function setOptions(array $options)
unset($options['help']);
}

// set default placeholder
// NEXT_MAJOR: Remove this.
if (!isset($options['placeholder'])) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not set, it will set a default, but if it is set to null, it won't, I think the new behavior you implemented don't cover this case

Copy link
Copy Markdown
Member Author

@VincentLanglet VincentLanglet Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isset(null) is false. So null wasn't the way to disable the placeholder. false is the way.

$options['placeholder'] = 'short_object_description_placeholder';
}

// NEXT_MAJOR: Remove this.
if (!isset($options['link_parameters'])) {
$options['link_parameters'] = [];
}
Expand Down
49 changes: 21 additions & 28 deletions src/FieldDescription/FieldDescriptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,38 @@

use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Exception\NoValueException;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\PropertyAccess\PropertyPathInterface;

/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* @phpstan-type FieldDescriptionOptions = array{
* accessor?: string|callable|PropertyPathInterface,
* actions?: array,
* admin_code?: string,
* associated_property?: string,
* block_name?: string,
* catalogue?: string,
* data_transformer?: DataTransformerInterface,
* edit?: string,
* editable?: bool,
* field_name?: string,
* field_options?: array,
* field_type?: string,
* header_class?: string,
* identifier?: bool,
* inline?: string,
* label?: bool|string|null,
* link_parameters?: array,
* multiple?: bool,
* placeholder?: string,
* required?: bool,
* accessor?: string|callable|\Symfony\Component\PropertyAccess\PropertyPathInterface,
* associated_property?: string|callable|\Symfony\Component\PropertyAccess\PropertyPathInterface,
* label?: string|false|null,
* link_parameters?: array<string, mixed>,
* role?: string|string[],
* route?: array,
* safe?: bool,
* sort_field_mapping?: array,
* sort_parent_association_mappings?: array,
* sort_field_mapping?: array<string, mixed>,
* sort_parent_association_mappings?: array<array<string, mixed>>,
* sortable?: bool,
* template?: string,
* timezone?: string|\DateTimeZone,
* translation_domain?: string,
* type?: string,
* virtual_field?: bool
* }
* }&array<string, mixed>
* @psalm-type FieldDescriptionOptions = (array{
* accessor?: string|callable|\Symfony\Component\PropertyAccess\PropertyPathInterface,
* associated_property?: string|callable|\Symfony\Component\PropertyAccess\PropertyPathInterface,
* label?: string|false|null,
* link_parameters?: array<string, mixed>,
* role?: string|string[],
* sort_field_mapping?: array<string, mixed>,
* sort_parent_association_mappings?: array<array<string, mixed>>,
* sortable?: bool,
* template?: string,
* translation_domain?: string,
* type?: string,
* virtual_field?: bool
* }&array<string, mixed>)|array<empty, empty>
*
* @method string|null getTargetModel()
* @method bool hasAdmin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ This code manages the many-to-[one|many] association field popup
'objectId': 'OBJECT_ID',
'uniqid': associationadmin.uniqid,
'code': associationadmin.code,
'linkParameters': sonata_admin.field_description.option('link_parameters')
'linkParameters': sonata_admin.field_description.option('link_parameters', {})
})}}'.replace('OBJECT_ID', objectId),
dataType: 'html',
success: function(html) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ file that was distributed with this source code.
'code': sonata_admin.field_description.associationadmin.code,
'objectId': sonata_admin.field_description.associationadmin.id(sonata_admin.value),
'uniqid': sonata_admin.field_description.associationadmin.uniqid,
'linkParameters': sonata_admin.field_description.option('link_parameters')
'linkParameters': sonata_admin.field_description.option('link_parameters', {})
})) }}
{% elseif sonata_admin.field_description.option('placeholder') %}
{% elseif sonata_admin.field_description.option('placeholder', 'short_object_description_placeholder') %}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can't be correct, otherwise it is an always true if and can be removed with just else

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To disabled the placeholder, 'false' should be use.

<span class="inner-field-short-description">
{{ sonata_admin.field_description.option('placeholder')|trans({}, 'SonataAdminBundle') }}
{{ sonata_admin.field_description.option('placeholder', 'short_object_description_placeholder')|trans({}, 'SonataAdminBundle') }}
</span>
{% endif %}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ file that was distributed with this source code.
'code': sonata_admin.field_description.associationadmin.code,
'objectId': sonata_admin.field_description.associationadmin.urlSafeIdentifier(sonata_admin.value),
'uniqid': sonata_admin.field_description.associationadmin.uniqid,
'linkParameters': sonata_admin.field_description.option('link_parameters')
'linkParameters': sonata_admin.field_description.option('link_parameters', {}))
})) }}
{% elseif sonata_admin.field_description.option('placeholder') %}
{% elseif sonata_admin.field_description.option('placeholder', 'short_object_description_placeholder') %}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

<span class="inner-field-short-description">
{{ sonata_admin.field_description.option('placeholder')|trans({}, 'SonataAdminBundle') }}
{{ sonata_admin.field_description.option('placeholder', 'short_object_description_placeholder')|trans({}, 'SonataAdminBundle') }}
</span>
{% endif %}
</span>
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/views/Form/form_admin_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,11 @@ file that was distributed with this source code.
'code': sonata_admin.field_description.associationadmin.code,
'objectId': sonata_admin.field_description.associationadmin.urlSafeIdentifier(sonata_admin.value),
'uniqid': sonata_admin.field_description.associationadmin.uniqid,
'linkParameters': sonata_admin.field_description.option('link_parameters')
'linkParameters': sonata_admin.field_description.option('link_parameters', {})
})) }}
{% elseif sonata_admin.field_description.option('placeholder') %}
{% elseif sonata_admin.field_description.option('placeholder', 'short_object_description_placeholder') %}
<span class="inner-field-short-description">
{{ sonata_admin.field_description.option('placeholder')|trans({}, 'SonataAdminBundle') }}
{{ sonata_admin.field_description.option('placeholder', 'short_object_description_placeholder')|trans({}, 'SonataAdminBundle') }}
</span>
{% endif %}
</span>
Expand Down