/[drupal]/contributions/modules/index/includes/index.admin.inc
ViewVC logotype

Diff of /contributions/modules/index/includes/index.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.3 by xano, Tue Nov 17 19:32:18 2009 UTC revision 1.1.2.4 by xano, Tue Nov 17 22:34:07 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: index.admin.inc,v 1.1.2.2 2009/11/17 19:23:38 xano Exp $  // $Id: index.admin.inc,v 1.1.2.3 2009/11/17 19:32:18 xano Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 56  function index_form_add(array $form_stat Line 56  function index_form_add(array $form_stat
56    
57    $form = array(    $form = array(
58      '#redirect' => 'admin/build/index',      '#redirect' => 'admin/build/index',
59      '#suffix' => '<div id="index-form-add-preview-page"><h2>' . t('Page preview') . '</h2><div class="content">' . $index->preview('page') . '</div></div><div id="index-form-add-preview-block"><h2>' . t('Block preview') . '</h2><div class="content">' . $index->preview('page') . '</div></div>',      '#suffix' => '<div id="index-form-add-preview-page"><h2>' . t('Page preview') . '</h2><div class="content">' . $index->view('page') . '</div></div><div id="index-form-add-preview-block"><h2>' . t('Block preview') . '</h2><div class="content">' . $index->view('block') . '</div></div>',
60    );    );
61    
62    // Internal settings.    // Internal settings.
# Line 334  function index_form_add_layers(index $in Line 334  function index_form_add_layers(index $in
334    
335  function _index_form_add_layers(array &$form, array $entity_types_info, array $entity_types_options, array $layers, $parent_entity_type = NULL, $depth = 0) {  function _index_form_add_layers(array &$form, array $entity_types_info, array $entity_types_options, array $layers, $parent_entity_type = NULL, $depth = 0) {
336    foreach ($layers as $layer) {    foreach ($layers as $layer) {
337        // TODO: There should not be two layers with the same entity type for any
338        // parent.
339      $layer_entity_types_options = $parent_entity_type ? array_intersect_key($entity_types_options, $entity_types_info[$parent_entity_type]['#relations']) : $entity_types_options;      $layer_entity_types_options = $parent_entity_type ? array_intersect_key($entity_types_options, $entity_types_info[$parent_entity_type]['#relations']) : $entity_types_options;
340      // Parent layers cannot be modified and are represented by a value element      // Parent layers cannot be modified and are represented by a value element
341      // for processing and an item element for the user to see.      // for processing and an item element for the user to see.
342      if (count($layer['children'])) {      if (count($layer->children)) {
343        $form['layer_type_' . $layer['lineage']] = array(        $form['layer_type_' . $layer->lineage] = array(
344          '#type' => 'value',          '#type' => 'value',
345          '#value' => $layer['entity_type'],          '#value' => $layer->entity_type,
346        );        );
347        $form['layer_type_item_' . $layer['lineage']] = array(        $form['layer_type_item_' . $layer->lineage] = array(
348          '#type' => 'item',          '#type' => 'item',
349          '#value' => $entity_types_info[$layer['entity_type']]['#title'],          '#value' => $entity_types_info[$layer->entity_type]['#title'],
350        );        );
351      }      }
352      // Layers that have no children can be modified.      // Layers that have no children can be modified.
353      else {      else {
354        $form['layer_type_' . $layer['lineage']] = array(        $form['layer_type_' . $layer->lineage] = array(
355          '#type' => 'select',          '#type' => 'select',
356          '#options' => $layer_entity_types_options,          '#options' => $layer_entity_types_options,
357          // Unconfigured layers get the first of the available values as their          // Unconfigured layers get the first of the available values as their
358          // default value.          // default value.
359          '#default_value' => !is_null($layer['entity_type']) ? $layer['entity_type'] : array_shift(array_keys($layer_entity_types_options)),          '#default_value' => !is_null($layer->entity_type) ? $layer->entity_type : array_shift(array_keys($layer_entity_types_options)),
360        );        );
361        $form['layer_count_' . $layer['lineage']] = array(        $form['layer_count_' . $layer->lineage] = array(
362          '#type' => 'checkbox',          '#type' => 'checkbox',
363          '#default_value' => $layer['count'],          '#default_value' => $layer->count,
364        );        );
365      }      }
366    
367      $form['layer_child_add_' . $layer['lineage']] = array(      $form['layer_child_add_' . $layer->lineage] = array(
368        '#type' => 'submit',        '#type' => 'submit',
369        '#value' => t('Add item'),        '#value' => t('Add item'),
370        '#submit' => array('index_form_add_update'),        '#submit' => array('index_form_add_update'),
# Line 374  function _index_form_add_layers(array &$ Line 376  function _index_form_add_layers(array &$
376        // impossible to detect the clicked button if multiple buttons have the        // impossible to detect the clicked button if multiple buttons have the
377        // same value. To fix this we configure a custom and unique name        // same value. To fix this we configure a custom and unique name
378        // (undocumented feature).        // (undocumented feature).
379        '#name' => 'layer_child_add_' . $layer['lineage'],        '#name' => 'layer_child_add_' . $layer->lineage,
380      );      );
381      $form['layer_remove_' . $layer['lineage']] = array(      $form['layer_remove_' . $layer->lineage] = array(
382        '#type' => 'submit',        '#type' => 'submit',
383        '#value' => t('Remove'),        '#value' => t('Remove'),
384        '#submit' => array('index_form_add_update'),        '#submit' => array('index_form_add_update'),
# Line 388  function _index_form_add_layers(array &$ Line 390  function _index_form_add_layers(array &$
390        // impossible to detect the clicked button if multiple buttons have the        // impossible to detect the clicked button if multiple buttons have the
391        // same value. To fix this we configure a custom and unique name        // same value. To fix this we configure a custom and unique name
392        // (undocumented feature).        // (undocumented feature).
393        '#name' => 'layer_remove_' . $layer['lineage'],        '#name' => 'layer_remove_' . $layer->lineage,
394      );      );
395    
396      $form['lineages']['#value'][$layer['lineage']] = $depth;      $form['lineages']['#value'][$layer->lineage] = $depth;
397      _index_form_add_layers($form, $entity_types_info, $entity_types_options, $layer['children'], $layer['entity_type'], $depth + 1);      _index_form_add_layers($form, $entity_types_info, $entity_types_options, $layer->children, $layer->entity_type, $depth + 1);
398    }    }
399  }  }
400    
401  /**  /**
402   * Write a rendered index to the screen for the AJAX preview.   * Write a rendered index to the screen for the AJAX preview.
403   */   */
404  function index_preview() {  function index_live_preview() {
405    index_load_include('classes');    index_load_include('classes');
406    
407    $index = new index();    $index = new index();
408    $index->title = $_GET['title'];    // Loop through all values and add them if the index accepts them.
409    $index->description = $_GET['description'];    foreach ($_GET as $property => $value) {
410    $index->page_enabled = isset($_GET['page_enabled']) ? $_GET['page_enabled'] : FALSE;      if (isset($index->$property)) {
411    $index->page_mode = $_GET['page_mode'];        $index->$property = $_GET[$property];
412    $index->block_enabled = isset($_GET['block_enabled']) ? $_GET['block_enabled'] : FALSE;      }
413    $index->block_mode = $_GET['block_mode'];    }
414    
415    drupal_json(array(    drupal_json(array(
416        'page' => $index->page_enabled ? $index->preview('page') : NULL,      'page' => $index->view('page'),
417        'block' => $index->block_enabled ? $index->preview('block') : NULL,      'block' => $index->view('block'),
418    ));    ));
419  }  }
420    

Legend:
Removed from v.1.1.2.3  
changed lines
  Added in v.1.1.2.4

  ViewVC Help
Powered by ViewVC 1.1.3