node_edit.inc
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010 function panels_node_edit_panels_arguments() {
00011 $args['node_edit'] = array(
00012 'title' => t("Node edit form"),
00013
00014 'keyword' => 'node',
00015 'description' => t('Displays the node edit form for a node.'),
00016 'context' => 'panels_node_edit_context',
00017 'settings form' => 'panels_node_edit_settings_form',
00018 'settings form submit' => 'panels_node_edit_settings_form_submit',
00019 'displays' => 'panels_node_edit_displays',
00020 'choose display' => 'panels_node_edit_choose_display',
00021 );
00022 return $args;
00023 }
00024
00025
00026
00027
00028 function panels_node_edit_context($arg = NULL, $conf = NULL, $empty = FALSE) {
00029
00030 if ($empty) {
00031 return panels_context_create_empty('node_edit_form');
00032 }
00033
00034 if (!is_numeric($arg)) {
00035 return FALSE;
00036 }
00037
00038 $node = node_load($arg);
00039 if (!$node) {
00040 return FALSE;
00041 }
00042
00043 if (array_filter($conf['types']) && empty($conf['types'][$node->type])) {
00044 return FALSE;
00045 }
00046
00047
00048 return panels_context_create('node_edit_form', $node);
00049 }
00050
00051
00052
00053
00054 function panels_node_edit_settings_form($conf) {
00055 $options = array();
00056 foreach (node_get_types() as $type => $info) {
00057 $options[$type] = $info->name;
00058 }
00059 $form['types'] = array(
00060 '#title' => t('Node types'),
00061 '#type' => 'checkboxes',
00062 '#options' => $options,
00063 '#description' => t('You can restrict this argument to use the checked node types. Arguments from non-conforming node types will be ignored, and Panels will behave as if no argument were given. Leave all unchecked to impose no restriction.'),
00064 '#default_value' => $conf['types'],
00065 '#prefix' => '<div class="clear-block">',
00066 '#suffix' => '</div>',
00067 );
00068
00069 $form['own_default'] = array(
00070 '#title' => t('Use different default display'),
00071 '#type' => 'checkbox',
00072 '#description' => t('If checked, when this argument is present it will use its own display rather than the default. Node types not selected in the "Own display" field will use this one.'),
00073 '#default_value' => $conf['own_default'],
00074 );
00075
00076 $form['displays'] = array(
00077 '#title' => t('Own display'),
00078 '#type' => 'checkboxes',
00079 '#options' => $options,
00080 '#default_value' => $conf['displays'],
00081 '#description' => t('Each checked node type will get its own special display to layout its content. Only node types set above should be set here. Node types not set here will use the default display.'),
00082 '#prefix' => '<div class="clear-block">',
00083 '#suffix' => '</div>',
00084 );
00085
00086 return $form;
00087 }
00088
00089
00090
00091
00092
00093
00094 function panels_node_edit_settings_form_submit(&$values) {
00095 $types = node_get_types();
00096 if (!empty($values['types'])) {
00097 foreach ($values['types'] as $type => $value) {
00098 if (empty($types[$type])) {
00099 unset($values['types'][$type]);
00100 }
00101 }
00102 }
00103 if (!empty($values['displays'])) {
00104 foreach ($values['displays'] as $type => $value) {
00105 if (empty($types[$type])) {
00106 unset($values['displays'][$type]);
00107 }
00108 }
00109 }
00110 }
00111
00112
00113
00114
00115 function panels_node_edit_displays($conf, $id) {
00116 $displays = array();
00117 if (!empty($conf['own_default'])) {
00118 $displays['default'] = array(
00119 'title' => t('Node edit form @id Default', array('@id' => $id)),
00120 'context' => 'node',
00121 );
00122 }
00123
00124 if (is_array($conf['displays'])) {
00125 $options = array();
00126 foreach (node_get_types() as $type => $info) {
00127 $options[$type] = $info->name;
00128 }
00129 foreach (array_keys(array_filter($conf['displays'])) as $type) {
00130 $displays[$type] = array(
00131 'title' => t('Node edit form @id @type', array('@id' => $id, '@type' => $options[$type])),
00132
00133 'default' => 'default',
00134 'context' => 'node',
00135 );
00136 }
00137 }
00138
00139 return $displays;
00140 }
00141
00142
00143
00144
00145 function panels_node_edit_choose_display($conf, $context) {
00146 if (empty($context->form)) {
00147 return;
00148 }
00149
00150 if (!empty($conf['displays'][$context->node_type])) {
00151 return $context->node_type;
00152 }
00153
00154
00155 if (!empty($conf['own_default'])) {
00156 return 'default';
00157 }
00158
00159
00160 return;
00161 }
00162