I'm using hook_form_alter to alter search block form (actualy i need to add a adv. search link. So i decidet to use markup element
$form['ad_search'] = array(
'#markup' => l('advanced search','search/node'),
'#weight' => 1000,
);
As mentioned in api: http://api.drupal.org/api/drupal/developer%21topics%21forms_api_referenc...
markup
Description: Generate generic markup for display inside forms. Note that there is no need to declare a form element as #type = 'markup', as this is the default type.
But search module produce a notice:
Notice: Undefined index: #type in function template_preprocess_search_block_form() (line 1070 in file /var/www/rating.local/modules/search/search.module).
I believe that line 1070
$type = $variables['form'][$key]['#type'];
must be changed to
$type = empty($variables['form'][$key]['#type']) ? 'markup' : $variables['form'][$key]['#type'];
Comment | File | Size | Author |
---|---|---|---|
#4 | drupal7x-search-block-undefined-index-1928690.patch | 1.03 KB | ovi.indrei |
Comments
Comment #1
marcingy CreditAttribution: marcingy commentedAs per http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.ht... type should be item
Comment #2
Heine CreditAttribution: Heine commented#markup is a valid property of #type markup and #type item elements.
So, either http://api.drupal.org/api/drupal/developer%21topics%21forms_api_referenc... is wrong, or there's a bug in form handling, where the default #type is not assigned.
Comment #3
yark CreditAttribution: yark commentedNot "should be" but "may be".
See example at that page uder markup section, not #markup:
When i alter add node form and adding markup fields all works without any notice:
Comment #4
ovi.indrei CreditAttribution: ovi.indrei commentedHere's a quick patch that fixes the issue. Please test and confirm that is fixed. Thanks.
Comment #5
yark CreditAttribution: yark commentedWorks for me. But i still belive that we need to assign 'markup' insead empty string. May be sometime later it needs to add special case for 'markup' as it done to hidden and token now.
includes/common.inc 5803..5807
drupal_render()
Comment #6
ovi.indrei CreditAttribution: ovi.indrei commentedThe hidden and token Form API #types are both hidden form fields and this is basically the reason why they get treated different than the rest of the fields. So I really don't think the markup element will ever get treated the same as the other hidden elements.
Comment #7
ovi.indrei CreditAttribution: ovi.indrei commentedSeems like nobody has anything else to add. Since this is a trivial fix, already confirmed to work, I'll push this issue to the next step. Feel free to intervene though, if you think it's the case.
Comment #8
marcingy CreditAttribution: marcingy commentedYou can't RTBC your own patches.
Comment #9
hazem.tamimi CreditAttribution: hazem.tamimi commented#4: drupal7x-search-block-undefined-index-1928690.patch queued for re-testing.
Comment #10
ovi.indrei CreditAttribution: ovi.indrei commented@marcingy, I know, I read the documentation, but I considered this to be the exception, because it's a very trivial fix.
Besides, @yark confirmed it is working. I thought things are supposed to move quicker with these quick fixes. Any feedback is welcomed.
Comment #11
michaelmol CreditAttribution: michaelmol commentedI ran into the same issue and can confirm the error isn't showing anymore.
Comment #12
ovi.indrei CreditAttribution: ovi.indrei commented#4: drupal7x-search-block-undefined-index-1928690.patch queued for re-testing.
Comment #13
kozmik CreditAttribution: kozmik commentedHad the same issue, can confirm that patch #4 resolves it without any other implications.
@ovidyou: thanks a ton!
Comment #14
ovi.indrei CreditAttribution: ovi.indrei commented#4: drupal7x-search-block-undefined-index-1928690.patch queued for re-testing.
Comment #15
ovi.indrei CreditAttribution: ovi.indrei commentedComment #16
malcomio CreditAttribution: malcomio commentedpatch #4 works fine for me too
Comment #17
David_Rothstein CreditAttribution: David_Rothstein commentedCommitted to 7.x - thanks! http://drupalcode.org/project/drupal.git/commit/af8d800
(And I confirmed that this doesn't appear to be an issue in Drupal 8.)