I have a content type with two Location CCK fields and need to force a default Location name for each of them, in order to user filter by location name in Views. In order to prevent users from altering the default location names, I am hiding the input from CSS. Additionally I would like to disable the Location Name form element, but have no idea how can I do this (I've been trying with form_alter), since it is a fieldset element. Any ideas? Thank you!

Comments

yesct’s picture

tagging.

rooby’s picture

Version: 6.x-3.0 » 6.x-3.1
Status: Active » Fixed

Note that this code is created for the 3.1 version, not the 3.0 version.

You can't use hook_form_alter() for this because at that stage the field is only a collections of the location settings used to create the fields that will be displayed.

The location module provides a hook for this, called hook_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL)
The field_expand $op is where locations fields are created and you can use that to modify the different fields of a location.

Here is an example that sets the default value for and then disables the 'name' field of the locations.
If you want you could add to this code some checks to determine which node type the user is currently adding/editing.

<?php
/**
 * Implementation of hook_locationapi().
 */
function mymodule_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
  switch ($op) {
    case 'field_expand':
      // For the field_expand $op, $a3 is the field name.
      switch ($a3) {
        case 'name':
          // This will be array_merged in with the field definition.
          return array(
            '#disabled' => 'TRUE',
            '#default_value' => 'This is the default text for the name field',
          );
      }
      break;
  }
}
?>

Status: Fixed » Closed (fixed)
Issue tags: -location theme edit form, -Location theming

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