'admin/panels/node-legacy', 'title' => t('Legacy node panes'), 'access' => user_access('access administration pages'), 'type' => MENU_NORMAL_ITEM, 'callback' => 'panels_node_legacy_admin', 'description' => t('Information about the legacy node content type.'), ); return $items; } } /** * Page callback for the very short admin page. */ function panels_node_legacy_admin() { $output = '

'; $output .= t('Panels legacy nodes does not have a normal administrative UI, such as panels pages or mini panels. With this module, users may add a node directly to a panel via the add content interface. They may then select this node using an auto-complete field. In general, this method of adding nodes to panes should be considered deprecated (especially by module developers implementing the Panels API) and is only retained to support updating sites that use this older method. Moving forward, it is recommended that the context system be used to embed nodes, as that is far more powerful and interesting.'); $output .= t('However, certain modules which make use of Panels are dependent on this method of getting node context (often without the developer even being aware of it), so it is important to emphasize that you CAN leave this module enabled without negatively impacting your site.'); $output .= '

'; return $output; } /** * Implementation of hook_panels_content_types() */ function panels_node_panels_content_types() { $items['node'] = array( 'title' => t('Node'), 'weight' => -10, 'single' => TRUE, 'content_types' => 'panels_node_legacy_content_types', 'render callback' => 'panels_node_legacy_render', 'add callback' => 'panels_node_legacy_add', 'edit callback' => 'panels_node_legacy_edit', 'title callback' => 'panels_node_legacy_title', 'add validate callback' => 'panels_node_legacy_edit_validate', 'edit validate callback' => 'panels_node_legacy_edit_validate', ); return $items; } /** * Output function for the 'node' content type. * * Outputs a node based on the module and delta supplied in the configuration. */ function panels_node_legacy_render($conf, $panel_args) { $nid = $conf['nid']; $block = new stdClass(); foreach (explode('/', $_GET['q']) as $id => $arg) { $nid = str_replace("%$id", $arg, $nid); } foreach ($panel_args as $id => $arg) { $nid = str_replace("@$id", $arg, $nid); } // Support node translation if (module_exists('translation')) { if ($translation = module_invoke('translation', 'node_nid', $nid, $GLOBALS['locale'])) { $nid = $translation; } } if (!is_numeric($nid)) { return; } $node = node_load($nid); if (!node_access('view', $node)) { return; } if (node_access('update', $node)) { $block->admin_links['update'] = array( 'title' => t('Edit node'), 'alt' => t("Edit this node"), 'href' => "node/$node->nid/edit", 'query' => drupal_get_destination(), ); } $block->module = 'node'; $block->delta = $node->nid; $block->subject = $node->title; if (empty($conf['leave_node_title'])) { unset($node->title); } if (!empty($conf['identifier'])) { $node->panel_identifier = $conf['identifier']; } $block->content = node_view($node, $conf['teaser'], FALSE, $conf['links']); return $block; } /** * Return all content types available. */ function panels_node_legacy_content_types() { return array( 'node' => array( 'title' => t('Node content'), 'icon' => 'icon_node.png', 'description' => t('Add a node from your site as content.'), 'category' => array(t('Custom'), -10), ), ); } /** * Returns the form for a new node. */ function panels_node_legacy_add($id, $parents, $conf = array()) { $form = panels_node_legacy_edit($id, $parents, $conf); $form['nid'] = array( '#prefix' => '
', '#suffix' => '
', '#title' => t('Enter the title or NID of a post'), '#description' => t('To use a NID from the URL, you may use %0, %1, ..., %N to get URL arguments. Or use @0, @1, @2, ..., @N to use arguments passed into the panel.'), '#type' => 'textfield', '#maxlength' => 512, '#autocomplete_path' => 'panels/node/autocomplete', '#weight' => -10, ); $form['validate_me'] = array('#type' => 'value', '#value' => TRUE); return $form; } /** * Returns an edit form for the custom type. */ function panels_node_legacy_edit($id, $parents, $conf) { $form['nid'] = array( '#type' => 'value', '#default_value' => $conf['nid'], ); $form['teaser'] = array( '#title' => t('Teaser'), '#type' => 'checkbox', '#default_value' => $conf['teaser'], '#description' => t('Check here to show only the node teaser'), ); $form['links'] = array( '#type' => 'checkbox', '#default_value' => $conf['links'], '#title' => t('Display links'), '#description' => t('Check here to display the links with the post.'), ); $form['leave_node_title'] = array( '#type' => 'checkbox', '#default_value' => $conf['leave_node_title'], '#title' => t('Leave node title'), '#description' => t('Advanced: if checked, do not touch the node title; this can cause the node title to appear twice unless your theme is aware of this.'), ); $form['identifier'] = array( '#type' => 'textfield', '#default_value' => $conf['identifier'], '#title' => t('Identifier'), '#description' => t('Whatever is placed here will appear in $node->panel_identifier to make it easier to theme a node or part of a node as necessary.'), ); return $form; } /** * Validate a node. */ function panels_node_legacy_edit_validate($form, $form_values) { if (!$form_values['validate_me']) { return; } if ($nid = panels_nid_autocomplete($form_values['nid'])) { form_set_value($form['nid'], $nid); } else { if (!preg_match('/^[@%]\d+$/', $form_values['nid'])) { form_error($form['nid'], t('Invalid node')); } } } /** * Returns the administrative title for a node. */ function panels_node_legacy_title($conf) { if (!is_numeric($conf['nid'])) { return t('Node loaded from @var', array('@var' => $conf['nid'])); } $node = node_load($conf['nid']); if ($node) { return check_plain($node->title); } else { return t('Deleted/missing node @nid', array('@nid' => $conf['nid'])); } }