You are here

function asset_panels_admin_gallery in Asset 6

Same name and namespace in other branches
  1. 5.2 contrib/asset_panels/asset_panels.module \asset_panels_admin_gallery()
  2. 5 asset_panels/asset_panels.module \asset_panels_admin_gallery()

Callback to perform administrative functions on the content block

1 string reference to 'asset_panels_admin_gallery'
asset_panels_panels_content_types in asset_panels/asset_panels.module
Callback function to supply a list of content types.

File

asset_panels/asset_panels.module, line 120

Code

function asset_panels_admin_gallery($op, &$arg, $arg2 = NULL) {
  switch ($op) {
    case 'list':
      $conf = $arg;
      $node = node_load($conf['nid']);
      return '<strong>Node</strong>: ' . check_plain($node->title);
    case 'add button':
      $form['nid'] = array(
        '#title' => t('Enter the title or NID of a post to gallerize its assets'),
        '#type' => 'textfield',
        '#maxlength' => 512,
        '#autocomplete_path' => 'panels/node/autocomplete',
        '#weight' => -10,
      );
      $form['submit'] = array(
        '#type' => 'button',
        '#value' => t('Add asset gallery'),
      );
      $form['#prefix'] = '<div class="container-inline">';
      $form['#suffix'] = '</div>';
      return $form;
    case 'add':
      if ($_POST['op'] != t('Add asset gallery')) {
        return;
      }
      $form =& $arg;
      if (is_numeric($form['nid'])) {
        $conf = array();
        $conf['nid'] = $form['nid'];
      }
      else {
        $conf = db_fetch_array(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE LOWER(title) = LOWER('%s')"), $form['nid']));
        if (!$conf['nid']) {
          drupal_set_message(t('Unable to find "%s"', array(
            '%s' => check_plain($form['nid']),
          )));
          return;
        }
      }

      // default to just teaser
      $conf['teaser'] = TRUE;
      return $conf;
    case 'edit':
      $conf =& $arg;
      $node = node_load($conf['nid']);
      $form['nid'] = array(
        '#type' => 'hidden',
        '#default_value' => $conf['nid'],
      );
      $form['asset_amount'] = array(
        '#type' => 'textfield',
        '#size' => 4,
        '#default_value' => $conf['asset_amount'] ? $conf['asset_amount'] : "2",
        '#title' => t('Amount of assets'),
        '#description' => t('How many assets should be displayed?'),
        '#required' => TRUE,
      );
      $form['asset_amount_per_page'] = array(
        '#type' => 'textfield',
        '#size' => 4,
        '#default_value' => $conf['asset_amount_per_page'] ? $conf['asset_amount_per_page'] : "4",
        '#title' => t('Amount of assets per page'),
        '#description' => t('How many assets should be displayed per page?'),
        '#required' => TRUE,
      );
      $form['create_block'] = array(
        '#type' => 'checkbox',
        '#default_value' => $conf['create_block'],
        '#title' => t('Create a block from this gallery?'),
      );
      $form['view_node'] = array(
        '#value' => t('<a href="@asset-gallery">View the original asset node</a>', array(
          '@asset-gallery' => url("node/" . $node->nid),
        )),
      );
      return $form;
    case 'validate':
      $form =& $arg;
      if (!is_numeric($form['asset_amount'])) {
        form_set_error('asset_amount', t('Amount should be a number.'));
      }
      elseif ($form['asset_amount'] <= 0) {
        form_set_error('asset_amount', t('Amount should be at least 1.'));
      }
      return;
    case 'save':

      // For this one, the form values go directly into the config.
      $form =& $arg;
      return $form;
  }
}