Remove #process pattern from taxo autocomplete widget

yched - November 10, 2009 - 00:46
Project:Drupal
Version:7.x-dev
Component:taxonomy.module
Category:task
Priority:normal
Assigned:Unassigned
Status:closed
Issue tags:D7 API clean-up
Description

Similar as #626354: Remove #process pattern from number field, but for taxonomy 'autocomplete' widget.
Seems to work OK according to my manual tests, let's see what the bot has to say.

The patch has @todo notes about a snippet I don't understand - bangpound, if you're around ?

AttachmentSizeStatusTest resultOperations
taxo_ac_widget_simplify.patch7.28 KBIdleFailed: 14615 passes, 67 fails, 128 exceptionsView details | Re-test

#1

System Message - November 10, 2009 - 01:05
Status:needs review» needs work

The last submitted patch failed testing.

#2

sun - November 10, 2009 - 01:26

subscribing

Nice usage of #element_validate! :)

#3

yched - November 10, 2009 - 02:34
Status:needs work» needs review

Heh, bug when the ac field was left empty. Every test that uses article node type soon finds out...

Try this one.

AttachmentSizeStatusTest resultOperations
taxo_ac_widget_simplify.patch7.43 KBIdleFailed: 14710 passes, 6 fails, 0 exceptionsView details | Re-test

#4

System Message - November 10, 2009 - 02:50
Status:needs review» needs work

The last submitted patch failed testing.

#5

bangpound - November 10, 2009 - 04:55

I'm here. I can't look at this for at least a day. I hope that's OK.

#6

sun - November 10, 2009 - 06:10

Sorry, not much time to review + test now, so just a quick one:

+++ modules/taxonomy/taxonomy.module 10 Nov 2009 02:33:50 -0000
@@ -1211,80 +1208,38 @@ function taxonomy_term_title($term) {
     '#attributes' => array('class' => array('text')),

This class should be "taxonomy-autocomplete" instead of "text".

This review is powered by Dreditor.

#7

yched - November 10, 2009 - 13:14

bangpund: no worries. To clarify, my question is:
In the current taxonomy_autocomplete_elements_process():

  // See if this element is in the database format or the transformed format,
  // and transform it if necessary.
  if (is_array($element['#value'])) {
    if (!array_key_exists($field_key, $element['#value'])) {
      // (branch 1)
    }
    else {
      // (branch 2)
    }
  }
  else {
    // (branch 3)
  }

what are the cases where branches 2 and 3 would be executed ?

#8

yched - November 10, 2009 - 18:47

re sun #6:
Hm, probably. Then again, I'm wondering if we *really* need the 'taxo autocomplete textfield' widget to have a 'custom width' setting (overriding node's default css, that puts a width: 95% style on all *node* forms, is the only reason for this specific class you mention - text and number widgets use the same workaround, and that class was copied from text.module)

Meanwhile, attached patch should fix the remaining failures.

Also, spin-off: #628642: Taxonomy field 'column' should be 'tid' instead of 'value'

AttachmentSizeStatusTest resultOperations
taxo_ac_widget_simplify.patch9.62 KBIdleFailed: Invalid PHP syntax in modules/taxonomy/taxonomy.test.View details | Re-test

#9

sun - November 10, 2009 - 18:32

You mean this?

<?php
  $element
[$field_key] = array(
   
'#type' => 'textfield',
...
   
'#size' => $instance['widget']['settings']['size'],
...
  );
 
$element[$field_key]['#maxlength'] = !empty($field['settings']['max_length']) ? $field['settings']['max_length'] : NULL;
?>

Yes, it makes neither sense to limit the length of a taxonomy autocomplete textfield, nor does it make sense to specify a width (size) for it. The former is totally nuts, and the latter is a pure theming/stylesheet job - hence, it should use a unique CSS class name.

#10

sun - November 10, 2009 - 18:33
Status:needs work» needs review

#11

yched - November 10, 2009 - 18:58

I mean more specifically

'#size' => $instance['widget']['settings']['size'],

The line about '#maxlength' was wrongly copied from text.module, and is removed for good in the patch. Taxonomy fields don't even have a 'max_length' settings to begin with ;-)

This being said, custom 'width' property for text and number fields was a much welcome feature when it was added back in CCK D(5 ? 4.7 ?). So I'm not sure it's really a theme thing. Besides, if the FAPI 'textfield' #type supports the #size attribute, it precisely assumes it's not a theme thing ;-)

So, all in all, it probably makes sense to leave the 'size' setting since text and number fields have it, and they all should use the same class to override node.css style.
I'll modify this in the patch later today.

#12

System Message - November 10, 2009 - 19:00
Status:needs review» needs work

The last submitted patch failed testing.

#13

sun - November 10, 2009 - 19:25

Maybe we should really move this into a separate issue, but...

and they all should use the same class to override node.css style

Absolutely definitely not. All form items get the generic .form-item class in addition to generic .form-type-[type] and .form-item-[name] classes, and all Form API textfields automatically get the generic .form-text class.

In the #type 'text_format' issue, I was already inclined to remove the additional "text" CSS class from those widgets, because it's mainly duplication of classification that already exists.

Themers need and want unique CSS class names that have a meaning and provide classification. Applying the identical "text" class to all widgets to override a generic styling for .form-text that happens elsewhere is wrong and does not help anyone. If we want to apply custom class names, then the class names should be unique and have a meaning to provide classification.

Also, applying a class on an inner form element of a field widget is wrong, because themers want to style the entire widget, not only the form element. Looking into field_default_form() again, it looks like we do not wrap a widget with a widget-specific container. So we should open a separate issue that turns $form_element into a #type container, automatically applying proper .field-type-[type] and .field-widget-[widget] classes, which, in turn, allows us to remove those classes from the individual form elements in the widgets.

#14

yched - November 10, 2009 - 19:57

Applying the identical "text" class to all widgets to override a generic styling for .form-text that happens elsewhere is wrong and does not help anyone

No, I meant applying a class named 'custom-width' or something, with only "width: auto" property, to support the feature of 'enter the width you want for your [text|number|taxo autocomplete] widget'. This is not different than classes used to support the 'display label above or inline' feature.

This feature is specific to some widget types, therefore it has to be applied by the widget, and cannot be applied by field_default_form() to a wrapper element.

Besides, this class is only needed because node.css has some IMO dumb styling that de facto makes FAPI's #width property ineffective in node forms (width: 95% or something).

#15

sun - November 10, 2009 - 20:59
Issue tags:+D7 API clean-up

Let's move this to #629074: Field widgets are not themeable due to missing CSS class names ;)

I'll try to review + test this patch later on.

#16

yched - November 11, 2009 - 00:57
Status:needs work» needs review

rerolled:
- removed the data massaging I wondered about in #7 - I'd still welcome bangpound's feedback before this is committed.
- removed the 'text' class as per #629074: Field widgets are not themeable due to missing CSS class names

AttachmentSizeStatusTest resultOperations
taxo_ac_widget_simplify.patch9.47 KBIdlePassed: 14695 passes, 0 fails, 0 exceptionsView details | Re-test

#17

bangpound - November 11, 2009 - 06:06

I did some research and found out the reasoning behind the data massaging. This code was introduced in the patch for #557932: Taxonomy term field autocomplete widgets never validate, always lose values., and we had a heck of a time coping with language codes in the process and validate functions.

Wow. The autocomplete widget is no longer incomprehensible. I'm really thankful for this patch.

#18

sun - November 11, 2009 - 07:18
Status:needs review» reviewed & tested by the community

Since this is no longer a #process, we cannot override "any preset #element_validate handlers" ;)

Moved that into $element. No other changes, hence, RTBC.

Whether there are potentially more clean-ups possible here, we should move into a separate issue.

And, yeah, @bangpound, the same reply we see in each of these issues ;) Awesome, yched!

AttachmentSizeStatusTest resultOperations
drupal.taxonomy-widget.18.patch9.44 KBIdlePassed: 14680 passes, 0 fails, 0 exceptionsView details | Re-test

#19

Dries - November 11, 2009 - 08:05

Good clean up except for one tiny little detail:

+++ modules/taxonomy/taxonomy.module 11 Nov 2009 07:06:56 -0000
@@ -1211,148 +1208,76 @@ function taxonomy_term_title($term) {
+      // otherwise, add create a new term.

Small typo here: 'add create'

#20

yched - November 11, 2009 - 13:26

Agreed with sun's #18.
Fixed the typo mentioned in #19.

AttachmentSizeStatusTest resultOperations
taxo_ac_widget_simplify-628188-20.patch9.48 KBIdlePassed: 14706 passes, 0 fails, 0 exceptionsView details | Re-test

#21

Dries - November 11, 2009 - 17:11
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks!

#22

yched - November 12, 2009 - 17:18

Followup for the @todo added in this patch: #631066: taxonomy_autocomplete() doesn't need to access $instance

#23

System Message - November 26, 2009 - 17:20
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.