Drupal 7 API Change notification: Four small-ish changes
*We try to notify this list when API changes are made in Drupal 7, so contrib and custom developers have a chance to fix their code before they have the pain of figuring out why it's broken. *(issue <http://drupal.org/node/140783>) Select elements in forms now require a default value by default. In the past, #required on a select element was kind of silly. Now it's on by default. So if you have a select element which is not supposed to allow submission without having a selection chosen, you have to set #required = FALSE. *Look carefully at this one if you have a select element in a form that you do not want to be #required.* (issue <http://drupal.org/node/844186#comment-3486946>) Database "merge queries" have changed syntax. If you used MergeQuery::updateExcept() in a merge query, you'll want to see the issue. *Look carefully at this one if you have a MergeQuery and use updateExcept(),* (issue <http://drupal.org/node/907690>) Meaning of MENU_CALLBACK has changed. It is only to be used for paths that are api callbacks only. If you're using it in any other context, of have child paths, things may break. *Look carefully at this one if you registered a MENU_CALLBACK menu item with hook_menu() that is not a plain vanilla path callback.* (issue <http://drupal.org/node/358437#comment-3503006>) Modules support a text format and format ID will need to deal with the fact that 0 is now an invalid format; NULL must be used instead. *Look carefully at this one if your module's schema has a 'format' column.* -- Randy Fay Drupal Module and Site Development randy@randyfay.com +1 970.462.7450
(issue <http://drupal.org/node/140783> ) Select elements in forms now require a default value by default. In the past, #required on a select element was kind of silly. Now it's on by default. So if you have a select element which is not supposed to allow submission without having a selection chosen, you have to set #required = FALSE. Look carefully at this one if you have a select element in a form that you do not want to be #required.
Sorry, this is not correct. Likely my fault, should've explained the API change more precisely. Select lists mostly behave as usual. However, if a select list does not have a #default_value or the #default_value is NULL, then the select list automatically gets an empty default option that asks the user to select an option. This is a security hardening improvement, because browsers automatically select the first available option in a select list, if no option has the "selected" attribute. This means that users were able to simply submit a form without ever having looked at the select list, and the form validated successfully. For your code, this means that you should set no #default_value (or NULL), in case you do not have a stored value for the select list, so the user is forced to choose a value. The empty default option only appears when there is no #default_value. Usually, you do not want to mark a select list explicitly as #required = TRUE (but of course you can do that). The empty default option can be tweaked with #empty_value (its value) and #empty_option (its label). See http://api.drupal.org/api/function/form_process_select/7 for details. Basically the same behavior has been implemented for select lists that are #required = FALSE. However, in that case, the empty option is always contained, so the user can choose "no value", whereas that actual value can be set via #empty_value (which defaults to an empty string). sun
On 9/29/2010 6:45 AM, Randy Fay wrote:
(issue <http://drupal.org/node/907690>) Meaning of MENU_CALLBACK has changed. It is only to be used for paths that are api callbacks only. If you're using it in any other context, of have child paths, things may break. /Look carefully at this one if you registered a MENU_CALLBACK menu item with hook_menu() that is not a plain vanilla path callback./
I don't understand this. breadcrumbs have always been messed up for MENU_CALLBACK items, but so here's the question: How do you get items to appear in the breadcrumb trail without making them MENU_NORMAL_ITEM and having them appear in navigation?
I don't understand this. breadcrumbs have always been messed up for MENU_CALLBACK items, but so here's the question: How do you get items to appear in the breadcrumb trail without making them MENU_NORMAL_ITEM and having them appear in navigation?
The difference is that MENU_CALLBACK items are really just invisible callbacks now; i.e., plain router items, not having any kind of menu link. For edge-cases like the given example, in which you have a router path that does not contain any dynamic path argument placeholder (%), you want to use 'type' => MENU_VISIBLE_IN_BREADCRUMB. We actually discussed whether we need a new constant, but since a new constant would be identical to MENU_VISIBLE_IN_BREADCRUMB, it would just have another name. sun
So does that mean that we need to improve the internal docs? Currently MENU_VISIBLE_IN_BREADCRUMB says "Internal menu flag -- menu item is visible in the breadcrumb" -Randy On Sun, Oct 3, 2010 at 11:12 AM, Daniel F. Kudwien <news@unleashedmind.com>wrote:
I don't understand this. breadcrumbs have always been messed up for MENU_CALLBACK items, but so here's the question: How do you get items to appear in the breadcrumb trail without making them MENU_NORMAL_ITEM and having them appear in navigation?
The difference is that MENU_CALLBACK items are really just invisible callbacks now; i.e., plain router items, not having any kind of menu link.
For edge-cases like the given example, in which you have a router path that does not contain any dynamic path argument placeholder (%), you want to use 'type' => MENU_VISIBLE_IN_BREADCRUMB.
We actually discussed whether we need a new constant, but since a new constant would be identical to MENU_VISIBLE_IN_BREADCRUMB, it would just have another name.
sun
-- Randy Fay Drupal Module and Site Development randy@randyfay.com +1 970.462.7450
On 10/3/2010 10:39 AM, Randy Fay wrote:
So does that mean that we need to improve the internal docs?
Currently MENU_VISIBLE_IN_BREADCRUMB says "Internal menu flag -- menu item is visible in the breadcrumb"
That sounds like a yes to me. Also is this true for Drupal 6 as well?
On Wed, Sep 29, 2010 at 9:45 AM, Randy Fay <randy@randyfay.com> wrote:
* *(issue <http://drupal.org/node/844186#comment-3486946>) Database "merge queries" have changed syntax. If you used MergeQuery::updateExcept() in a merge query, you'll want to see the issue. *Look carefully at this one if you have a MergeQuery and use updateExcept(),*
MergeQuery::update() was also affected by this API change as we learnt in http://drupal.org/node/924532 - in our case, replacing it with MergeQuery::updateFields() was all we had to do. Steph.
participants (4)
-
Daniel F. Kudwien -
Earl Miles -
Randy Fay -
Stéphane Corlosquet