Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Add fragment backoffice title and improve validation #22

Merged
merged 3 commits into from Dec 2, 2016

Conversation

qsomazzi
Copy link
Member

@qsomazzi qsomazzi commented Dec 1, 2016

Changelog

### Added
- Fragment "Backoffice title"

### Changed
- FragmentService `buildEditForm` now call `buildForm` to add backoffice title to each fragments
- FragmentService validate signature

Subject

The goal of this PR is to handle new backoffice title for each fragments. This improve the readability of the admin, instead of seeing only the fragment type, you will see a label related to your content. Also, the validate signature was wrong, because it's called from the article admin.

Before

capture d ecran 2016-12-01 a 10 46 49

After

capture d ecran 2016-12-01 a 10 46 07

@@ -134,21 +154,26 @@
e.preventDefault();
e.stopPropagation();

var sure = confirm("The fragment will be deleted after update. Are you sure?");

if (!sure) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This variable is used only once. Why not just write

if (!confirm("The fragment will be deleted after update. Are you sure?")) {
{
}

@@ -134,21 +154,26 @@
e.preventDefault();
e.stopPropagation();

var sure = confirm("The fragment will be deleted after update. Are you sure?");
Copy link
Contributor

Choose a reason for hiding this comment

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

No i18n?

@qsomazzi qsomazzi force-pushed the improve_fragments branch 3 times, most recently from 7488de3 to 740f0b6 Compare December 1, 2016 12:13
@qsomazzi
Copy link
Member Author

qsomazzi commented Dec 2, 2016

Hello @sonata-project/contributors, we really need this merge by the morning, can we merge it please ?

@qsomazzi
Copy link
Member Author

qsomazzi commented Dec 2, 2016

One required check can't be launched but i don't know why

@greg0ire
Copy link
Contributor

greg0ire commented Dec 2, 2016

I'll talk to @soullivaneuh about that

@qsomazzi
Copy link
Member Author

qsomazzi commented Dec 2, 2016

thanks @greg0ire

@greg0ire
Copy link
Contributor

greg0ire commented Dec 2, 2016

BTW, shouldn't this be split into 2 commits? It looks like you are doing 2 separate things here.

@greg0ire
Copy link
Contributor

greg0ire commented Dec 2, 2016

@soullivaneuh unstuck StyleCI, but you have to force push to trigger it.

{
if (empty($object->getBackofficeTitle())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there a more Symfony-ish way of doing this, by using the NotBlank constraint?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could save you some translations…

Copy link
Member Author

Choose a reason for hiding this comment

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

the whole validation part is still a work in progress, for the moment we can't use symfony constraints, we are working on that on another PR. I will add the todo in doc.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

@qsomazzi qsomazzi force-pushed the improve_fragments branch 2 times, most recently from 88c53d0 to 834aeee Compare December 2, 2016 09:49
@qsomazzi
Copy link
Member Author

qsomazzi commented Dec 2, 2016

@greg0ire I've split it in 3 (to be more precise)

@@ -42,8 +42,13 @@ public function buildCreateForm(FormMapper $form, FragmentInterface $fragment);
*
* @param FragmentInterface $fragment
* @param ExecutionContextInterface $context
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Uuuh… what?

* @var int
* @var string
*/
protected $backofficeTitle;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be private

Copy link
Member Author

Choose a reason for hiding this comment

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

can't set it private, all other properties are protected, and we used them (on fixtures for exemple)

Copy link
Contributor

Choose a reason for hiding this comment

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

ok leave it as is then

@@ -1,6 +1,6 @@
{% block form %}
{% set fragmentName = admin.fragmentServices[form.vars.data.type].name %}
<div data-fragment-form="{{ form.vars.id }}" data-form-tmp="true" data-formdata='{ "name": "Fragment {{ fragmentName }}", "type": "{{ fragmentName }}" }' data-errors="{{ form.vars.errors|length }}">
<div data-fragment-form="{{ form.vars.id }}" data-form-tmp="true" data-formdata='{ "name": "Fragment {{ fragmentName }}", "type": "{{ form.vars.data.backofficeTitle }}" }' data-errors="{{ form.vars.errors|length }}">
Copy link
Contributor

Choose a reason for hiding this comment

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

Linebreak this please

@@ -9,7 +9,7 @@
</h4>
</div>
<div class="box-body">
{% if form.vars.errors|length > 0 %}
{% if form.vars.errors is defined and form.vars.errors|length > 0 %}
Copy link
Contributor

Choose a reason for hiding this comment

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

form.vars.errors|default([])|lenght would be shorter, but the best would be to have this variable always defined

Todo
====

This bundle is still a work in progress, we need to work more on some part.
Copy link
Contributor

Choose a reason for hiding this comment

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

"parts"

@@ -9,7 +12,7 @@
</h4>
</div>
<div class="box-body">
{% if form.vars.errors|length > 0 %}
{% if form.vars.errors|default([])|lenght > 0 %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you test this? Beware, this is a trick question…

Copy link
Member Author

Choose a reason for hiding this comment

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

honestly no, i've trust your knowledge :) will do give me 2min :p

Copy link
Contributor

Choose a reason for hiding this comment

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

Good answer ;) I mispellt length, and you copied it, that's why I'm asking

Copy link
Member Author

Choose a reason for hiding this comment

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

@greg0ire all good now :)

@greg0ire
Copy link
Contributor

greg0ire commented Dec 2, 2016

@sonata-project/contributors , please review and merge

}

this._elementsIndex++;
console.log('[Sonata.Admin] [fragments|add] current index is ' + this._elementsIndex);
Copy link
Member

Choose a reason for hiding this comment

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

Admin.log and not console.log

@rande rande merged commit 18daa99 into sonata-project:master Dec 2, 2016
@qsomazzi qsomazzi deleted the improve_fragments branch December 2, 2016 15:08
@OskarStark
Copy link
Member

OskarStark commented Mar 23, 2017

I mark this PR as minor instead of major, as there is no current release

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants