2001-12-06 17:33:05 +00:00
<?php
// $Id$
2004-08-21 06:42:38 +00:00
/**
* @file
* Enables users to submit stories, articles or similar content.
*/
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_help().
2004-03-10 09:32:46 +00:00
*/
2004-05-08 07:17:47 +00:00
function story_help($section) {
2003-08-21 18:21:15 +00:00
switch ($section) {
2005-11-01 10:17:34 +00:00
case 'admin/help#story':
$output = '<p>'. t('The story module is used to create a content post type called <em>stories.</em> Stories are articles in their simplest form: they have a title, a teaser and a body. Stories are typically used to post news articles or as a group blog. ') .'</p>';
$output .= '<p>'. t('The story administration interface allows for complex configuration. It provides a submission form, workflow, default view permission, default edit permission, permissions for permission, and attachments. Trackbacks can also be enabled.') .'</p>';
$output .= t('<p>You can</p>
<ul>
<li>post a story at <a href="%node-add-story">create content >> story</a>.</li>
2006-01-29 07:50:45 +00:00
<li>configure story at <a href="%admin-settings-content-types-story">administer >> settings >> content types >> configure story</a>.</li>
2005-11-01 10:17:34 +00:00
</ul>
2006-01-29 07:50:45 +00:00
', array('%node-add-story' => url('node/add/story'), '%admin-settings-content-types-story' => url('admin/settings/content-types/story')));
2006-02-21 18:46:54 +00:00
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%story">Story page</a>.', array('%story' => 'http://drupal.org/handbook/modules/story/')) .'</p>';
2005-11-01 10:17:34 +00:00
return $output;
2004-06-18 15:04:37 +00:00
case 'admin/modules#description':
2005-04-01 15:55:02 +00:00
return t('Allows users to submit stories, articles or similar content.');
2004-01-27 18:47:07 +00:00
case 'node/add#story':
2005-01-15 08:01:09 +00:00
return t('Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extended by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.');
2003-08-21 18:21:15 +00:00
}
2002-02-25 20:26:38 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2005-08-29 19:58:49 +00:00
* Implementation of hook_node_info().
2004-03-10 09:32:46 +00:00
*/
2005-08-29 19:58:49 +00:00
function story_node_info() {
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
return array('story' => array('name' => t('story'), 'base' => 'story'));
2001-12-06 17:33:05 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_perm().
2004-03-10 09:32:46 +00:00
*/
2002-12-10 20:35:20 +00:00
function story_perm() {
2004-07-13 20:40:46 +00:00
return array('create stories', 'edit own stories');
2002-12-10 20:35:20 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_access().
2004-03-10 09:32:46 +00:00
*/
2001-12-06 17:33:05 +00:00
function story_access($op, $node) {
2004-03-10 09:32:46 +00:00
global $user;
2004-05-08 07:17:47 +00:00
if ($op == 'create') {
2004-03-10 09:32:46 +00:00
return user_access('create stories');
}
2004-07-31 09:30:09 +00:00
if ($op == 'update' || $op == 'delete') {
if (user_access('edit own stories') && ($user->uid == $node->uid)) {
return TRUE;
}
2001-12-06 17:33:05 +00:00
}
}
2004-06-18 15:04:37 +00:00
/**
* Implementation of hook_menu().
*/
2004-09-16 07:17:56 +00:00
function story_menu($may_cache) {
2004-06-18 15:04:37 +00:00
$items = array();
2004-09-16 07:17:56 +00:00
if ($may_cache) {
$items[] = array('path' => 'node/add/story', 'title' => t('story'),
2004-12-04 10:00:22 +00:00
'access' => user_access('create stories'));
2004-09-16 07:17:56 +00:00
}
2004-06-18 15:04:37 +00:00
return $items;
}
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_form().
2004-03-10 09:32:46 +00:00
*/
2004-07-04 16:50:02 +00:00
function story_form(&$node) {
2006-01-18 19:29:17 +00:00
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5);
2006-01-19 08:54:41 +00:00
$form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
- Patch #45530 by Morbus: filter_form shouldn't default to #weight 0
When a form element doesn't specify a #weight, it is assumed internally as #weight 0. However, to ensure that our form elements display visually *as they were defined in the array* we, in form_builder, count the number of elements, divide by 1000, and set that as the weight:
# Assign a decimal placeholder weight to preserve original array order
if (!isset($form[$key]['#weight'])) {
$form[$key]['#weight'] = $count/1000;
}
The above code will set the #weights of elements that have not defined a weight to something like 0 (first element in array definition), 0.001, 0.002, and so on. However, anytime a form element *explicitly* defines a #weight of 0, that #weight is kept at exactly 0, which would cause that form element to appear BEFORE the elements that didn't have a #weight defined (and thus received a #weight such as 0.002).
Consider the following pseudo example:
$form['game_title'] = array(
'#type' => 'textfield',
...
);
$form['game_description'] = array(
'#type' => 'textarea',
...
);
$form['game_format'] = filter_form(variable_get('game_format', NULL));
return $form;
Here, we're not definiing weights on our two textfields. We then add an filter_form. The second parameter of the filter_form is $weight, which defaults to 0. After this $form hits form_builder, we have weights 0 (game_title), 0.001 (game_description), and 0 (filter_form) respectively. This is then sorted by weight, which causes filter_form (the third element in the array) to appear BEFORE game_description (0 is lighter than 0.001).
The short lesson is: explicitly defining #weight 0 for a form element is probably a bad idea. This patch changes the default #weight of filter_form to NULL, instead of 0, and also removes any other explicit setting of #weight to 0 in core.
2006-01-20 09:04:34 +00:00
$form['body_filter']['format'] = filter_form($node->format);
2005-10-07 06:11:12 +00:00
return $form;
2001-12-06 17:33:05 +00:00
}