function crumbs_Admin_ElementObject_WeightsTabledrag::process in Crumbs, the Breadcrumbs suite 7.2
Callback for $element['#process'] Create one textfield element per rule.
Parameters
array $element:
array $form_state:
Return value
array
Overrides crumbs_Admin_ElementObject_Abstract::process
File
- lib/
Admin/ ElementObject/ WeightsTabledrag.php, line 52
Class
Code
function process($element, $form_state) {
/** @var crumbs_PluginSystem_PluginInfo $info */
$info = $element['#crumbs_plugin_info'];
$default_weights = $info->defaultWeights;
$available_keys_meta = $info->availableKeysMeta;
$sections = array(
'enabled' => t('Enabled'),
'disabled' => t('Disabled'),
);
foreach ($default_weights as $value) {
if (FALSE === $value) {
$sections['default:disabled'] = t('Disabled by default');
}
else {
$sections["default:{$value}"] = t('!key: !value', array(
'!key' => t('Default weight'),
'!value' => t('Disabled'),
));
}
}
$sections['inherit'] = t('Inherit');
// Set up sections
foreach ($sections as $section_key => $section_title) {
$element["sections.{$section_key}"] = array(
'#tree' => TRUE,
'#title' => $section_title,
'weight' => array(
'#type' => 'hidden',
'#default_value' => 'section',
),
'#section_key' => $section_key,
);
}
// Set up tabledrag rows
foreach ($available_keys_meta as $key => $meta) {
$child = array(
'#title' => $key,
'weight' => array(
'#type' => 'textfield',
'#size' => 10,
'#default_value' => -1,
'#class' => array(
'crumbs-weight-element',
),
),
'#section_key' => 'inherit',
'#crumbs_rule_info' => $meta,
);
$element["rules.{$key}"] = $child;
}
foreach ($default_weights as $key => $value) {
if (FALSE === $value) {
$element["rules.{$key}"]['#section_key'] = 'default:disabled';
}
else {
$element["rules.{$key}"]['#section_key'] = "default:{$value}";
}
}
if (is_array($element['#value'])) {
foreach ($element['#value'] as $key => $value) {
if (isset($element["rules.{$key}"])) {
$child =& $element["rules.{$key}"];
if (FALSE === $value) {
$child['#section_key'] = 'disabled';
}
elseif (is_numeric($value)) {
$child['weight']['#default_value'] = $value;
$child['#section_key'] = 'enabled';
}
}
}
}
return $element;
}