function organigrams_form_organigrams in Organigrams 7
Create or edit an organigram form.
Parameters
array $form: The form being used to edit the node.
array $form_state: The form state array.
array $edit: The object to update.
Return value
mixed Renderable array containing a form.
1 string reference to 'organigrams_form_organigrams'
- organigrams_menu in ./
organigrams.module - Implements hook_menu().
File
- ./
organigrams.admin.inc, line 111 - Defines the administration forms for managing organigrams.
Code
function organigrams_form_organigrams($form, &$form_state, $edit = array()) {
// During initial form build, add the entity to the form state for use
// during form building and processing. During a rebuild, use what is in
// the form state.
if (!isset($form_state['organigram'])) {
// Convert the edit variable to an object.
$organigram = is_object($edit) ? $edit : (object) $edit;
// Create array with default values.
$default = array(
'name' => '',
'machine_name' => '',
'description' => '',
'status' => 1,
'canvas_width' => 'auto',
'canvas_height' => 'auto',
'center' => 0,
'fit' => 0,
'node_width' => 120,
'node_height' => 30,
'top_radius' => 0,
'bottom_radius' => 0,
'shadow_offset' => 0,
'horizontal_space' => 20,
'vertical_space' => 20,
'horizontal_offset' => 30,
'line_color' => '',
'border_color' => '',
'border_color_hover' => '',
'background_color' => '',
'background_color_hover' => '',
'font_color' => '',
'font_color_hover' => '',
'font_name' => '',
'font_size' => '',
'line_height' => '',
'vertical_alignment' => 1,
'weight' => 0,
);
// Iterate through default values.
foreach ($default as $key => $value) {
// If the property is missing.
if (!isset($organigram->{$key})) {
// Then add the default value.
$organigram->{$key} = $value;
}
}
// Assign organigram to the form state.
$form_state['organigram'] = $organigram;
}
else {
// Retrieve the organigram from the form state.
$organigram = $form_state['organigram'];
}
// Add organigram to the form.
$form['#organigram'] = $form_state['organigram'];
// Load the extra fields information so set the correct order.
$extrafields = field_info_extra_fields('organigrams', 'organigrams', 'form');
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t('The name of the organigram is used as title.'),
'#default_value' => $organigram->name,
'#maxlength' => 255,
'#required' => TRUE,
'#weight' => isset($extrafields['name']['weight']) ? $extrafields['name']['weight'] : 0,
);
$form['machine_name'] = array(
'#type' => 'machine_name',
'#default_value' => $organigram->machine_name,
'#maxlength' => 255,
'#machine_name' => array(
'exists' => 'organigrams_machine_name_load',
),
);
$form['old_machine_name'] = array(
'#type' => 'value',
'#value' => $organigram->machine_name,
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#description' => t('The description can used as an explanatory text.'),
'#default_value' => $organigram->description,
'#weight' => isset($extrafields['#description']['weight']) ? $extrafields['#description']['weight'] : 1,
);
$form['status'] = array(
'#type' => 'checkbox',
'#title' => t('Published'),
'#description' => t('Unpublished organigrams will not be displayed on the website.<br />Note that users with the permission to edit this organigram will still be able to see this organigram.'),
'#default_value' => $organigram->status,
'#weight' => isset($extrafields['status']['weight']) ? $extrafields['status']['weight'] : 2,
);
// Canvas settings.
$form['canvas'] = array(
'#type' => 'fieldset',
'#title' => t('organigram settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => isset($extrafields['organigram_settings']['weight']) ? $extrafields['organigram_settings']['weight'] : 3,
);
$form['canvas']['canvas_width'] = array(
'#type' => 'textfield',
'#title' => t('organigram width'),
'#description' => t('Specify the width in pixels of the organigram.<br /><br />Other available options:<br /><br /><ul><li><b>auto</b>: Calculate the width by the number of items</li><li><b>parent</b>: Adjust the width to the parent element of the organigram.</li></ul>'),
'#default_value' => $organigram->canvas_width,
);
$form['canvas']['canvas_height'] = array(
'#type' => 'textfield',
'#title' => t('organigram height'),
'#description' => t('Specify the height in pixels of the organigram. The same options as width are available here.'),
'#default_value' => $organigram->canvas_height,
);
$form['canvas']['center'] = array(
'#type' => 'checkbox',
'#title' => t('Center on page'),
'#description' => t('Aligns the organigram on the center of the page.'),
'#default_value' => $organigram->center,
);
$form['canvas']['fit'] = array(
'#type' => 'checkbox',
'#title' => t('Fit in given width'),
'#description' => t('Scale the organigram to fit in the given width.'),
'#default_value' => $organigram->fit,
);
$form['canvas']['line_color'] = array(
'#type' => 'textfield',
'#title' => t('Line color'),
'#description' => t('Specify the connection lines color in this organigram.'),
'#default_value' => $organigram->line_color,
'#attributes' => array(
'class' => array(
'colorpicker',
),
),
);
// Node settings.
$form['node'] = array(
'#type' => 'fieldset',
'#title' => t('Item settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => isset($extrafields['item_settings']['weight']) ? $extrafields['item_settings']['weight'] : 4,
);
$form['node']['node_width'] = array(
'#type' => 'textfield',
'#title' => t('Item width'),
'#description' => t('Specify the width in pixels of the items in this organigram.'),
'#default_value' => $organigram->node_width,
);
$form['node']['node_height'] = array(
'#type' => 'textfield',
'#title' => t('Item height'),
'#description' => t('Specify the height in pixels of the items in this organigram.'),
'#default_value' => $organigram->node_height,
);
$form['node']['top_radius'] = array(
'#type' => 'textfield',
'#title' => t('Top radius'),
'#description' => t('Specify the radius of the top corners in pixels of the items in this organigram.'),
'#default_value' => $organigram->top_radius,
);
$form['node']['bottom_radius'] = array(
'#type' => 'textfield',
'#title' => t('Bottom radius'),
'#description' => t('Specify the radius of the bottom corners in pixels of the items in this organigram.'),
'#default_value' => $organigram->bottom_radius,
);
$form['node']['shadow_offset'] = array(
'#type' => 'textfield',
'#title' => t('Shadow offset'),
'#description' => t('Specify the shadow offset in pixels of the items in this organigram.'),
'#default_value' => $organigram->shadow_offset,
);
$form['node']['horizontal_space'] = array(
'#type' => 'textfield',
'#title' => t('Horizontal space'),
'#description' => t('Specify the horizontal space in pixels between the items in this organigram.'),
'#default_value' => $organigram->horizontal_space,
);
$form['node']['vertical_space'] = array(
'#type' => 'textfield',
'#title' => t('Vertical space'),
'#description' => t('Specify the vertical space in pixels between the items in this organigram.'),
'#default_value' => $organigram->vertical_space,
);
$form['node']['horizontal_offset'] = array(
'#type' => 'textfield',
'#title' => t('Horizontal offset'),
'#description' => t('Specify the horizontal offset in pixels between the l and r items in this organigram.'),
'#default_value' => $organigram->horizontal_offset,
);
$form['node']['border_color'] = array(
'#type' => 'textfield',
'#title' => t('Border color'),
'#description' => t('Specify the border color of the items in this organigram.'),
'#default_value' => $organigram->border_color,
'#attributes' => array(
'class' => array(
'colorpicker',
),
),
);
$form['node']['border_color_hover'] = array(
'#type' => 'textfield',
'#title' => t('Border color hover'),
'#description' => t('Specify the border color of the items in this organigram on hover if they have a URL.'),
'#default_value' => $organigram->border_color_hover,
'#attributes' => array(
'class' => array(
'colorpicker',
),
),
);
$form['node']['background_color'] = array(
'#type' => 'textfield',
'#title' => t('Background color'),
'#description' => t('Specify the background color of the items in this organigram.'),
'#default_value' => $organigram->background_color,
'#attributes' => array(
'class' => array(
'colorpicker',
),
),
);
$form['node']['background_color_hover'] = array(
'#type' => 'textfield',
'#title' => t('Background color hover'),
'#description' => t('Specify the background color of the items in this organigram on hover if they have a URL.'),
'#default_value' => $organigram->background_color_hover,
'#attributes' => array(
'class' => array(
'colorpicker',
),
),
);
// Font settings.
$form['font'] = array(
'#type' => 'fieldset',
'#title' => t('Font settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => isset($extrafields['font_settings']['weight']) ? $extrafields['font_settings']['weight'] : 5,
);
$form['font']['font_color'] = array(
'#type' => 'textfield',
'#title' => t('Font color'),
'#description' => t('Specify the font color of the items in this organigram.'),
'#default_value' => $organigram->font_color,
'#attributes' => array(
'class' => array(
'colorpicker',
),
),
);
$form['font']['font_color_hover'] = array(
'#type' => 'textfield',
'#title' => t('Font color hover'),
'#description' => t('Specify the font color of the items in this organigram on hover if they have a URL.'),
'#default_value' => $organigram->font_color_hover,
'#attributes' => array(
'class' => array(
'colorpicker',
),
),
);
$form['font']['font_name'] = array(
'#type' => 'textfield',
'#title' => t('Font name'),
'#description' => t('Specify the font name of the items in this organigram.'),
'#default_value' => $organigram->font_name,
);
$form['font']['font_size'] = array(
'#type' => 'textfield',
'#title' => t('Font size'),
'#description' => t('Specify the font size in pixels of the items in this organigram.'),
'#default_value' => $organigram->font_size,
);
$form['font']['line_height'] = array(
'#type' => 'textfield',
'#title' => t('Line height'),
'#description' => t('Specify the line height in pixels for the text in the items in this organigram.'),
'#default_value' => $organigram->line_height,
);
$form['font']['vertical_alignment'] = array(
'#type' => 'select',
'#title' => t('Vertical text alignment'),
'#description' => t('Specify the vertical text alignment of the items in this organigram.'),
'#options' => array(
0 => t('Top'),
1 => t('Center'),
),
'#default_value' => $organigram->vertical_alignment,
);
// Add supported actions for this form.
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
// Attach the ColorPicker library if it exists.
$form['#attached']['libraries_load'][] = array(
'colorpicker',
);
$library = libraries_detect('colorpicker');
if (!empty($library['installed'])) {
$form['#attached']['js'][] = drupal_get_path('module', 'organigrams') . '/js/colorpicker.js';
}
// Add fields to the form.
field_attach_form('organigrams', $organigram, $form, $form_state);
// Return the generated form.
return $form;
}