Create Custom Content type Module with User access and content permission
Component ID
2061947
Component name
Create Custom Content type Module with User access and content permission
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Component created
Component changed
Component body
Create Module info file " job_post.info " :
name = Job post
description = Create custom content type.
core = 7.x
package = Cutom content type(Gajendra Sharma)
files[] = job_post.install
files[] = job_post.module
And, Create Module file " job_post.module " :
function job_post_install() {
$t = get_t(); // runs in both the installer and runtime
/* Create and save a new content object */
$job_post = 'job_post'; // machine name of the content type
// define the node type
$job_post_type = array(
'type' => $job_post,
'name' => $t('job_post'),// Display name of the content type
'base' => 'node_content',
'title_label' => $t('Title'),
'description' => $t('To add images and captions.'),
'custom' => TRUE,
);
// set other node defaults not declared above
$content_type = node_type_set_defaults($job_post_type);
// add the body field
node_add_body_field($content_type, $t('Body'));
// save the content type
node_type_save($content_type);
}
function job_post_node_info(){
return array(
'job_post'=>array(
'name'=> t('Job Post title'),
'base'=>'job_post',
'description'=>t('Create custom content type'),
'has_title'=>TRUE,
'title_label'=>t('MY Job Post'),
'help'=>t('Enter the JOb title and description of the company'),
),
);
}
function job_post_permission(){
return array(
'create new job post'=>array(
'title'=>t('create new job post'),
'description'=>t('create new job post'),),
'edit own job post'=>array(
'title'=>t('edit own job post'),
'description'=>t('edit own job post'),),
'delete own job post'=>array(
'title'=>t('delete own job post'),
'description'=> t('delete own job post'),),
'delete any job post'=>array(
'title'=>t('delete any job post'),
'description'=> t('delete any job post'),),
);
}
function job_post_form($node , $form_state){
// drupal default provide tile and body fields:
return node_content_form($node,$form_state);
}
function job_post_node_access($op, $node, $account) {
$is_author = $account->uid == $node->uid;
switch ($op) {
case 'create':
if (user_access('create job', $account)) {
return NODE_ACCESS_ALLOW;
}
case 'update':
if (user_access('edit own job', $account) && $is_author ||
user_access('edit any job', $account)) {
return NODE_ACCESS_ALLOW;
}
case 'delete':
if (user_access('delete own job', $account) && $is_author ||
user_access('delete any job', $account)) {
return NODE_ACCESS_ALLOW;
}
}
}