Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Scyther’s picture

Status: Active » Needs review
FileSize
6.22 KB

Patch:
- Moves the title field to the first add flag form and changes the name field to machine-name type.
- When going from the first form page to the second one, when adding a new flag, the flag is stored temp in a cache table with ctools. (Taken insperation from Views)
- Adds dependencies for ctools for using the cache meantion above.
- Not allowed to change the name (machine-name) after the flag is saved. Good or bad?!?!
- The url for the second form when adding flag has been changed from admin/structure/flags/add/*type*/*name* to admin/structure/flags/add/*name* because the type is not longer needed because it is saved in the temporary cached flag.

There is things that could be improved and I will try to get time to work on thoose and make a new patch. Please give some feedback.

Status: Needs review » Needs work

The last submitted patch, flag_machine_name_field-1689400-2.patch, failed testing.

Scyther’s picture

Status: Needs work » Needs review
FileSize
6.82 KB

New patch with updated DrupalWebTestCase.

Status: Needs review » Needs work

The last submitted patch, flag_machine_name_field-1689400-4.patch, failed testing.

joachim’s picture

Thanks for working on this!!

> the flag is stored temp in a cache table with ctools. (Taken insperation from Views)
> - Adds dependencies for ctools for using the cache meantion above.

Ouch. Do we really need to add a dependency just for this?
I know CTools is pretty popular now since Views needs it (and who builds a site without views) but adding the dependency just for a UI tweak seems a bit much.

I'm wondering whether the approach ought to be to take the name field off the type selection form entirely, and have a menu callback for the flag add form that takes a type argument. Would need some path tweaking:

- '/manage/%flag/edit' edits a named, existing flag
- 'add/TYPE' would need to present the edit form but for a new, empty flag.

Scyther’s picture

Status: Needs work » Needs review
FileSize
6.75 KB

Here is a new patch without the dependency for CTools.

I'm wondering whether the approach ought to be to take the name field off the type selection form entirely, and have a menu callback for the flag add form that takes a type argument. Would need some path tweaking:

- '/manage/%flag/edit' edits a named, existing flag
- 'add/TYPE' would need to present the edit form but for a new, empty flag.

Sounds good, will take a look a this and make a new patch.

Status: Needs review » Needs work

The last submitted patch, flag_machine_name_field-1689400-7.patch, failed testing.

Scyther’s picture

Status: Needs work » Needs review
FileSize
6.37 KB

Patch with thoose changes you proposed.

Patches that I have made so far, you can't change the name (machine name) of the flag after it's saved. Good or bad?

socketwench’s picture

Status: Needs review » Needs work
+++ b/includes/flag.admin.incundefined
@@ -289,7 +262,22 @@ function flag_form($form, &$form_state, $flag) {
+    '#title' => t('Flag name'),

Personally, I find "Flag name" confusing for the #title. I'd rather it read "Machine name". What does View's do?

EDIT: I'm also concerned that this patch would blow up when #1681540: replace 'content' with 'entity', eg $content_type with $entity_type gets in.

joachim’s picture

Yikes! Bigger patch than I thought!

> Personally, I find "Flag name" confusing for the #title. I'd rather it read "Machine name".

I agree.

+++ b/includes/flag.admin.inc
@@ -247,17 +238,14 @@ function flag_add_form($form, &$form_state) {
-  $errors = $flag->validate_name();
-  foreach ($errors as $field => $field_errors) {
-    foreach ($field_errors as $error) {
-      form_set_error($field, $error['message']);
-    }

This needs to move to the flag edit form.

+++ b/includes/flag.admin.inc
@@ -289,7 +262,22 @@ function flag_form($form, &$form_state, $flag) {
+    '#disabled' => !empty($flag->fid), // Don't allow to change the machine name after the flag is saved. Good or bad??

IIRC we currently allow changing of the machine name, with caveats. So I'd say we should keep that functionality.

> EDIT: I'm also concerned that this patch would blow up when #1681540: replace 'content' with 'entity', eg $content_type with $entity_type gets in.

Everything's going to blow up then.... :)

Scyther’s picture

Status: Needs work » Needs review
FileSize
5.52 KB

> Personally, I find "Flag name" confusing for the #title. I'd rather it read "Machine name".

Fixed

> IIRC we currently allow changing of the machine name, with caveats. So I'd say we should keep that functionality.

Fixed

+++ b/includes/flag.admin.inc
@@ -247,17 +238,14 @@ function flag_add_form($form, &$form_state) {
-  $errors = $flag->validate_name();
-  foreach ($errors as $field => $field_errors) {
-    foreach ($field_errors as $error) {
-      form_set_error($field, $error['message']);
-    }

> This needs to move to the flag edit form.
Does it? Machine name field has it own validation and does it same as $flag->validate_name() does. See form_validate_machine_name()
Also in in flag_form_validate(), $flag->validate() is called which calls $this->validate_name().

joachim’s picture

> Does it? Machine name field has it own validation and does it same as $flag->validate_name

Oh. Yes, you're right. Sorry!

socketwench’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

socketwench’s picture

Status: Reviewed & tested by the community » Fixed
joachim’s picture

On 3.x? I really hope that doesn't break the monster rename patch...!

joachim’s picture

Status: Fixed » Needs work

This breaks my local branch at #1681540: replace 'content' with 'entity', eg $content_type with $entity_type.

I'm afraid I think we're going to have to revert this, then get 1681540 in, then come back to this. Sorry!

joachim’s picture

Reverted the commit. Sorry!

Scyther’s picture

No problem. I will update my patch as soon as the "monster patch" is applied :)

socketwench’s picture

My fault, should have realized that would happen. >_<

Scyther’s picture

Status: Needs work » Needs review
FileSize
5.92 KB
joachim’s picture

Status: Needs review » Needs work

Looking good!

Could you change the title on the first add page to 'Select flag type' please? And then I think we're good to go!

(Another tweak we could make is to move the radio buttons description up to hook_help() text, but that's something to tackle in another issue: #1718744: move description on flag type radio buttons to hook_help.)

Scyther’s picture

Status: Needs work » Needs review

Patch updated.

- 'Select flag type' title on the first add page.
- 'Add new @type flag' title on the second add page.
- Changed title for the action link for adding new flag, from 'Add a new flag' to 'Add flag'.
- Changed value for the submit button on the first add page from 'Add flag' to 'Continue'.

Scyther’s picture

And here is the patch

joachim’s picture

Status: Needs review » Fixed

Thanks!

I'm committing this with a fix for the couple of tabbed lines and whitespace changes that crept in.

For future reference, do resist the urge to fix other stuff in a patch -- such as this which as far as I can tell just makes the variable name nicer:

-  drupal_set_message(t('Flag @name has been saved.', array('@name' => $flag->get_title())));
+  drupal_set_message(t('Flag @title has been saved.', array('@title' => $flag->get_title())));

and fixing the strtolower to drupal_strtolower.

Those are all good fixes, but remember the kittens! :)

- Issue #1689400 by Scyther: Changed flag form to use machine name form element.
- by Scyther: Fixed use of strtolower().

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.