simplenews prepopulation improvement

This commit is contained in:
Bachir Soussi Chiadmi
2014-04-25 15:11:39 +02:00
parent d7dddd5764
commit 9d2fee4ddd
4 changed files with 197 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
<?php
<?php
/**
@@ -17,6 +17,43 @@ function materio_admin_permission() {
);
}
/**
* Implements hook_menu().
*/
function materio_admin_menu() {
if(module_exists('simplenews')){
$cats = simplenews_category_list();
dsm($cats, 'cats');
foreach ($cats as $tid => $name) {
// $items['node/%node/simplenews'] = array(
// 'title' => 'Newsletter',
// 'type' => MENU_LOCAL_TASK,
// 'access callback' => 'simplenews_node_tab_access',
// 'access arguments' => array(1),
// 'page callback' => 'simplenews_node_tab_page',
// 'page arguments' => array(1),
// 'context' => MENU_LOCAL_TASK,
// 'file' => 'includes/simplenews.admin.inc',
// 'weight' => 2,
// );
$items['node/add/simplenews/'.$tid] = array(
'title' => $name,
'title callback' => 'check_plain',
'page callback' => 'node_add',
'page arguments' => array('simplenews'),
'access callback' => 'node_access',
'access arguments' => array('create', 'simplenews'),
// 'description' => $type->description,
'file path' => drupal_get_path('module', 'node'),
'file' => 'node.pages.inc',
'options' => array('query'=>array('cat'=>$tid))
);
}
}
return $items;
}
/**
* Implements hook_menu_alter().
*/
@@ -27,18 +64,26 @@ function materio_admin_menu_alter(&$items){
$items['admin/people']['access arguments'] = array('access default users list');
// dsm($items['admin/people']);
}
if(isset($items['admin/people/expiration'])){
$items['admin/people/expiration']['access arguments'] = array('access default UC roles expiration list');
// dsm($items['admin/people/expiration']);
}
# deactivate default home page
$items['node']['access callback'] = FALSE;
// if(isset($items['admin/content/add/simplenews'])){
// delete($items['admin/content/add/simplenews']);
// $cats = simplenews_category_list();
// dsm($cats, 'cats');
// foreach ($cats as $tid => $name) {
// $items['admin/content/add/simplenews/'.$tid]
// }
// }
}
/**
* Implements hook_form_alter().
*/
@@ -51,29 +96,20 @@ function materio_admin_form_simplenews_node_form_alter(&$form, &$form_state, $fo
if(!$form['nid']['#value']){
if(isset($_GET['cat'])){
$cat = $_GET['cat'];
switch($cat){
case 6374:
$template = 'daily';
break;
case 6274:
$template = 'news';
break;
}
// prepopulate type of news
$form['field_simplenews_term']['und']['#default_value'] = $cat;
$form['field_simplenews_term']['und']['#disabled'] = true;
// change default template regarding type of news
$form['body']['und'][0]['#default_value'] = materio_admin_getSimplenewsNodeBodyTemplate($template);
$form['body']['und'][0]['#rows'] = 50;
$form['body']['und'][0]['#default_value'] = materio_admin_getSimplenewsNodeBodyTemplate($cat);
$form['body']['und'][0]['#rows'] = 50;
}
}else{
$form['field_simplenews_term']['und']['#disabled'] = true;
}
}
function materio_admin_getSimplenewsNodeBodyTemplate($template){
return file_get_contents(drupal_get_path('module', 'materio_admin').'/templates/simplenews_'.$template.'_node_template.html');
function materio_admin_getSimplenewsNodeBodyTemplate($cat){
return file_get_contents(drupal_get_path('module', 'materio_admin').'/templates/simplenews_'.$cat.'_node.html');
}