This is the issue.
I have a block called 'User Favorites Block'
It's placed in the region 'First Sidebar'
'First Sidebar' appears on the front-page.
The function is supposed to grab the data from the f25_favorites table and list them inside the block. Right now the table is an empty array.
When I return $output, none of my divs or anything are output.
When I do print($output), everything is displayed.
This is my test code to show that my 'if' statement is returning true. http://d.pr/zDph
/*
* f25_favorites_my_favorites theme
*/
function theme_f25_favorites_my_favorites($mypaths) {
dsm($mypaths);
print_r(count($mypaths));
$output .= 'n<div id="f25-favorites">n';
$output .= '<div id="f25-favorites-list">n';
if (count($mypaths) == 0) {
$output .= "No favorites have been added";
print "No favorites have been added";
}
else {
foreach ($mypaths as $indpath) {
$output .= l($indpath->title, $indpath->path, $attributes = array());
}
}
$output .= '</div>n';
$output .= '<div id="f25-favorites-add">n';
$output .= '</div>n';
$output .= 'n</div>n';
return $output;
}
This outputs this: http://d.pr/Uhrs
Note the 0 on the top left, that's the output of the 'count()'
And the print of the text within the 'if'
So, this is my theme:
/*
* f25_favorites_my_favorites theme
*/
function theme_f25_favorites_my_favorites($mypaths) {
/*dsm($mypaths);
print_r(count($mypaths));*/
$output .= '\n<div id="f25-favorites">\n';
$output .= '<div id="f25-favorites-list">\n';
if (count($mypaths) == 0) {
$output .= "No favorites have been added";
}
else {
foreach ($mypaths as $indpath) {
$output .= l($indpath->title, $indpath->path, $attributes = array());
}
}
$output .= '</div>\n';
$output .= '<div id="f25-favorites-add">\n';
$output .= '</div>\n';
$output .= '\n</div>\n';
return $output;
}
It's called with this hook_theme() function:
/*
* Implentation of hook_theme().
*/
function f25_favorites_theme () {
return array(
'f25_favorites_my_favorites' => array (
'arguments' => array ('mypaths' => array())
),
);
}
Which is called with this hook_block() function:
/*
* Implementation of hook_block().
*
*/
function f25_favorites_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$blocks = array();
$blocks['f25-favorites'] = array(
'info' => t('User Favorites Block'),
'cache' => BLOCK_NO_CACHE,
);
return $blocks;
}
if ($op == 'view') {
switch ($delta) {
case 0:
$mypaths = f25_favorites_user_favorites();
$block = array(
'subject' => t('User Favorites Block'),
'content' => theme_f25_favorites_my_favorites($mypaths)
);
return $block;
};
}
}
Noteworthy
My theme is a 'Sub-theme' of a theme called 'Zen'
Zen has a block.tpl.php which looks like this: http://d.pr/AaO1
Here is the full code of my module: http://d.pr/cGqc
It could be a region-related problem. Try switching to Garland and add the block to a plain old Garland region, and see if it appears.
If you see it in Garland then make sure your sub-theme really is defining that "First Sidebar" region and then actually printing its variable in the tpl files.
(FWIW I tried your code on Garland and it displays the block fine.)
Also, you might want to change your function call from:
theme_f25_favorites_my_favorites($mypaths)
to:
theme('f25_favorites_my_favorites', $mypaths)
...if you want to keep the code flexible (i.e. have Drupal call any preprocess functions and allow other people, or yourself in the future, to override the template's output)
Related
I've taken over managing our site from MIA developers and have spent the day trying to find this answer.
After upgrading to v 7.56 there's just ONE specific page in a list of pages that I am unable to access as an admin. (and unfortunately it's probably the most needed report in our admin panel).
Here's what I know:
Drupal Version 7.56
PHP 7.0.20
No errors when status report is run
Chron - no errors
Here's what I've done:
added $cookie_domain = '.example.com'; to settings.php
cleared browser cache and cookies
ensured admin has access to everything
cleared site cache
made sure code on page(s) was exactly the same as it was before I did the update
Not sure what to do or where to go from here. Any help is much appreciated.
UPDATE: When logged in as super admin, received HTTP 500 error. After more research, I updated the php.ini to include memory_limit = 64M ;
Now I can view the page as the superadmin, but it still isn't available for other admins.
Image 1: viewing page as admin
Image 2: viewing page as superadmin
function custom_reports_menu() {
$items['administration/upcoming-classes'] = array(
'title' => 'Upcoming Classes',
'page callback' => 'custom_reports_upcoming_classes_page',
'access callback' => 'user_access',
'access arguments' => array('admin wdcc reports'),
'file' => 'includes/custom_reports.upcoming-classes.inc',
'type' => MENU_CALLBACK,
);
$items['administration/class-details'] = array(
'title' => 'Class Details',
'page callback' => 'custom_reports_class_details_page',
'access callback' => 'user_access',
'access arguments' => array('admin wdcc reports'),
'file' => 'includes/custom_reports.class-details.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
function custom_reports_upcoming_classes_page() {
drupal_add_css(base_path().path_to_theme().'/assets/css/outburst-accounts.css', array('type' => 'external'));
global $user;
$uid = $user->uid;
$output = '';
$upcoming_classes = custom_reports_get_upcoming_classes();
$attendee_count = custom_reports_get_attendee_count();
// upcoming classes
$output .= '<h2>Upcoming Classes</h2>';
$output .= custom_reports_format_upcoming_classes($upcoming_classes, $attendee_count);
return $output;
}
function custom_reports_permission() {
return array(
'admin wdcc reports' => array(
'title' => t('Admin WDCC Reports'),
'description' => t('Perform administration tasks for WDCC.'),
//'cache' => DRUPAL_NO_CACHE,
),
);
}
function custom_reports_get_upcoming_classes() {
$today = date('Y-m-d');
$x = 0;
$classes = '';
// get classes from new db tables
$today = date('Y-m-d H:i:s');
$result = db_query("SELECT n.nid FROM node n, field_data_field_date fdfd WHERE n.status = :status AND n.type = :type AND n.nid = fdfd.entity_id AND fdfd.field_date_value >= :today ORDER BY fdfd.field_date_value ASC", array(':status' => 1, ':type' => 'public_class_date', ':today' => $today));
if ($result->rowCount() > 0) {
foreach ($result as $row) {
$nid = $row->nid;
$node = node_load($nid);
$product_id = $nid;
$product_title = $node->title;
$product_type = 'public_class_date';
$product_date = $node->field_date[$node->language][0]['value'];
$product_datestamp = strtotime($product_date);
//$product_datestamp = strtotime($product_date);
// set vars
$classes[$x]['product_id'] = $product_id;
$classes[$x]['product_title'] = $product_title;
$classes[$x]['product_type'] = $product_type;
$classes[$x]['product_date'] = $product_date;
$classes[$x]['product_datestamp'] = $product_datestamp;
$x++;
}
}
return $classes;
}
function custom_reports_get_attendee_count() {
$attendees = array();
$old_attendees = array();
$new_attendees = array();
$result = db_query("SELECT itemID, attendeeID, attendeeName FROM wdcc_old_attendee");
if ($result->rowCount() > 0) {
foreach ($result as $row) {
$item_id = $row->itemID;
$attendee_id = 'B'.$row->attendeeID;
$attendee_name = $row->attendeeName;
$old_attendees[$item_id][$attendee_id]['old_attendee_id'] = $attendee_id;
if (strpos($attendee_name, '&') > 0 || strpos($attendee_name, ' and') > 0) { // couples
$old_attendees[$item_id][$attendee_id]['total_attendees'] = 2;
} else {
$old_attendees[$item_id][$attendee_id]['total_attendees'] = 1;
}
}
}
if (is_array($old_attendees)) {
$connect_class_ids = custom_accounts_connect_class_ids();
foreach ($old_attendees as $old_item_id => $attendee_list) {
if (isset($connect_class_ids[$old_item_id])) {
$product_id = $connect_class_ids[$old_item_id];
foreach ($attendee_list as $attendee_id => $attendee) {
$old_attendee_id = $attendee['old_attendee_id'];
$attendees[$product_id][$old_attendee_id]['total_attendees'] = $attendee['total_attendees'];
}
}
}
}
$result = db_query("SELECT id, product_id FROM wdcc_attendees WHERE transaction_id > 0");
if ($result->rowCount() > 0) {
foreach ($result as $row) {
$attendee_id = $row->id;
$product_id = $row->product_id;
$attendees[$product_id][$attendee_id]['total_attendees'] = 1;
}
}
$cancelled_attendees = array();
$result = db_query("SELECT * FROM wdcc_attendees_cancelled");
if ($result->rowCount() > 0) {
foreach ($result as $row) {
$attendee_id = $row->attendee_id;
$old_attendee_id = 'B'.$row->old_attendee_id;
if ($attendee_id > 0) {
$cancelled_attendees[] = $attendee_id;
} else {
$cancelled_attendees[] = $old_attendee_id;
}
}
}
foreach ($attendees as $product_id => $product_attendees) {
foreach ($product_attendees as $attendee_id => $attendee) {
if (in_array($attendee_id, $cancelled_attendees)) {
unset($attendees[$product_id][$attendee_id]);
}
}
}
$attendee_count = array();
foreach ($attendees as $product_id => $product_attendees) {
foreach ($product_attendees as $attendee_id => $attendee) {
if (!isset($attendee_count[$product_id])) {
$attendee_count[$product_id] = $attendee['total_attendees'];
} else {
$attendee_count[$product_id] = $attendee_count[$product_id] + $attendee['total_attendees'];
}
}
}
return $attendee_count;
}
function custom_reports_format_upcoming_classes($upcoming_classes, $attendee_count) {
$output = '';
if (is_array($upcoming_classes)) {
$output .= '<div class="table-responsive table-container">';
$output .= '<table class="table">';
$output .= '<tr><td>Class</td><td>Guests</td><td>Actions</td></tr>';
foreach ($upcoming_classes as $class) {
$nid = $class['product_id'];
$node_url = url('node/'.$nid, array('absolute' => TRUE));
$attendees = 0;
if (isset($attendee_count[$nid])) {
$attendees = $attendee_count[$nid];
}
$output .= '<tr><td>'.$class['product_title'].'<br />'.date('m/d/Y - g:i A', $class['product_datestamp']).'</td><td>'.$attendees.'</td><td>View roster</td></tr>';
}
$output .= '</table>';
$output .= '</div>';
} else {
$output .= '<p>No upcoming classes found.</p>';
}
return $output;
}
Probably would need more info, but it seems like a case of custom or hardcoded permissions.
Here's potential cases to explore:
Assign all the roles to the admin user
Search custom modules for this page URL. See if page is only certain users are allowed to access this page.
If report is Drupal View, find this view and check the permissions section.
In the current menu items you are using access callback attribute in a wrong way. Your menu items do not require to specify access callback. Only access argument is sufficient.
Please add an access argument to which only admin has access.
"access callback": A function returning TRUE if the user has access rights to this menu item, and FALSE if not. It can also be a boolean constant instead of a function, and you can also use numeric values (will be cast to boolean). Defaults to user_access() unless a value is inherited from the parent menu item; only MENU_DEFAULT_LOCAL_TASK items can inherit access callbacks. To use the user_access() default callback, you must specify the permission to check as 'access arguments' (see below).
Source: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7.x
Replace this below code in settings.php file
PHP variable name:
$cookie_domain = 'example.com'; (line 340)
I was getting this error while login Drupal. After lots of reacher I found that we mistakenly blocked some internal IP of Drupal which is trigger while login the Drupal. So my suggestion is here Your should have to check if you have block any IP at your end (index.php file or anywhere). And You can TRUNCATE the Table session and flood from DB it also help you out.
I'd like the have the output of the html return two possible markups based on a parameter the user can set. The parameter text_mode will be defined by the user by adding basic or advanced.
Right now, the $output is set for testing to show the basic version whereby the user's string is wrapped in a <p>. If the text_mode is set to advanced, then it's not wrapped.
<?php
function PCHiddenTextBlock( $settings = array() ) {
//---- Get Settings ----
//The functions default settings will be merged with what's passed in.
$settingsDefault = array(
'small_heading' => '',
'text' => '',
'text_mode' => 'basic', //or advanced
'color_scheme' => 'accent4',//accent4 or accent1
'container_id' => '',
'container_class' => 'x_extraContent',
);
$settings = array_merge($settingsDefault, $settings);
//---- Set Variables ----
//These will allow the markup build up to be as clean as possible.
//If container_id is set, prepare the attribute
$has_container_id = strlen($settings['container_id']) > 0;
$possible_container_id_attribute = ($has_container_id) ? " id='{$settings['container_id']}'" : "";
//Color scheme variables
switch($settings['color_scheme']) {
case 'accent1':
$gcol_color_class = 'bg-color-accent1-C';
$color_accent_class = 'color-accent1-8';
$hover_color_class = 'hover-color-base-4';
break;
default: //accent4
$gcol_color_class = 'bg-color-accent4-D';
$color_accent_class = 'color-accent4-A';
$hover_color_class = 'hover-color-base-4';
}
//---- Build Output ----
//Line by line, concatenating strings with new line and tab characters.
$output = "\n<!-- Hidden Text Block -->";
$output .= "\n<div class='{$settings['container_class']} gcol-1 {$gcol_color_class}'{$possible_container_id_attribute}>";
$output .= "\n\t<div class='padbox-standard-content'>";
$output .= "\n\t\t<h2 class='small-heading color-accent1-9'>{$settings['small_heading']}</h2>";
$output .= "\n\t\t<p>{$settings['text']}</p>"; // basic version
$output .= "\n\t\t<a href='' class='x_extraContentClose box-close-icon {$color_accent_class} {$hover_color_class}'></a>";
$output .= "\n\t</div><!-- padbox-standard-content-->";
$output .= "\n</div><!-- Hiddent Text Block -->";
//---- Return Output ----
return $output;
}
Just use an if statement:
if ($settings['text_mode'] == 'basic') {
$output .= "\n\t\t<p>{$settings['text']}</p>"; // basic version
} else {
$output .= "\n\t\t{$settings['text']}<"; // advanced version
}
I have constructed a shortcode like this:
[myshortcode id="4"]content[/myshortcode]
with this:
<?php
function f_shortcode($atts, $content = null) {
$returned_string = '<div class="wrap">';
$returned_string .= '<div class="frame">'.$content.'</div>';
$returned_string .= '</div>';
return $returned_string;
}
add_shortcode('myshortcode', 'f_shortcode');
?>
What i need from my shortcode is to retrieve a record from option table in the database (i.e retrieve content based on the id given in the shortcode)
In the options table i have this:
a:1:{i:0;O:8:"stdClass":4:{s:2:"id";s:1:"4";s:9:"title";s:5:"test";s:11:"content";s:5:"test content";s:13:"shortcode";s:29:"[myshortcode id="4"][/myshortcode id="4"]";}}
So to retrieve the content i have added this peace of code to my function:
extract(shortcode_atts(array(
'id' => 'id'
), $atts));
if(get_option('results_options') && get_option('results_options') != ''){
$results = get_option('results_options');
foreach ($results as $result){
if($result->id == '{$id}'){
$content = $result->content;
continue;
}
}
}
In my table the content is there, but it doesnt display or it doesnt even be retrieved, Is there a problem with my code ?
How to get the id="4" parametre inside the function to retrieve the record from the database with it ?
I have been working on moodle 2.7 framework, my requirement is i wanted to show 2 different custom menu for Teacher and Student Role, at present I have created custom menu in template options, but I have no idea how to create multiple custom menu in moodle. so far I tried doing it by searching group id and then use if statement to assign custom menu but still no output, so I request can anybody help me to sort this issues.
You can extend the custom menu - https://docs.moodle.org/dev/Extending_the_theme_custom_menu
Then use has_capability() to see if the user can see the menu item.
Something like this (I haven't tried it)
// theme/themename/renderers.php
class theme_themename_core_renderer extends core_renderer {
protected function render_custom_menu(custom_menu $menu) {
$context = context_system::instance();
if (has_capability('local_plugin/menuname:view', $context)) {
$branchlabel = get_string('menuname', 'local_myplugin');
$branchurl = new moodle_url('/local/myplugin/index.php');
$branchtitle = $branchlabel;
$branchsort = 10000;
$branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
}
return parent::render_custom_menu($menu);
}
}
Russell,
below is code from renderes.php
<?php
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This plugin is part of Archaius theme.
#copyright 2013 Daniel Munera Sanchez
*/
class theme_archaius_core_renderer extends core_renderer {
/**
* Prints a nice side block with an optional header.
*
* The content is described
* by a {#link block_contents} object.
*
* #param block_contents $bc HTML for the content
* #param string $region the region the block is appearing in.
* #return string the HTML to be output.
*/
function block(block_contents $bc, $region) {
$bc = clone($bc); // Avoid messing up the object passed in.
if (empty($bc->blockinstanceid) || !strip_tags($bc->title)) {
$bc->collapsible = block_contents::NOT_HIDEABLE;
}
if ($bc->collapsible == block_contents::HIDDEN) {
$bc->add_class('hidden');
}
if (!empty($bc->controls)) {
$bc->add_class('block_with_controls');
}
$skiptitle = strip_tags($bc->title);
if (empty($skiptitle)) {
$output = '';
$skipdest = '';
} else {
$output = html_writer::tag('a', get_string('skipa', 'access', $skiptitle), array('href' => '#sb-' . $bc->skipid, 'class' => 'skip-block'));
$skipdest = html_writer::tag('span', '', array('id' => 'sb-' . $bc->skipid, 'class' => 'skip-block-to'));
}
$title = '';
if ($bc->title) {
$title = html_writer::tag('h2', $bc->title);
}
$controlshtml = $this->block_controls($bc->controls);
if ($title || $controlshtml) {
$output .= html_writer::tag('div', html_writer::tag('div', $title , array('class' => 'title')), array('class' => 'header-tab'));
}
$output .= html_writer::start_tag('div', $bc->attributes);
if ($title || $controlshtml) {
$output .= html_writer::tag('div', html_writer::tag('div', html_writer::tag('div', '', array('class'=>'block_action')). $title . $controlshtml, array('class' => 'title')), array('class' => 'header'));
}
$output .= html_writer::start_tag('div', array('class' => 'content'));
if (!$title && !$controlshtml) {
$output .= html_writer::tag('div', '', array('class'=>'block_action notitle'));
}
$output .= $bc->content;
if ($bc->footer) {
$output .= html_writer::tag('div', $bc->footer, array('class' => 'footer'));
}
$output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('div');
if ($bc->annotation) {
$output .= html_writer::tag('div', $bc->annotation, array('class' => 'blockannotation'));
}
$output .= $skipdest;
$this->init_block_hider_js($bc);
return $output;
}
/*
* From boostrapbase
* Overriding the custom_menu function ensures the custom menu is
* always shown, even if no menu items are configured in the global
* theme settings page.
*/
public function custom_menu($custommenuitems = '') {
global $CFG;
//TODO: Check this in a different way
$langs = get_string_manager()->get_list_of_translations();
if ( (count($langs) < 2) and (empty($CFG->custommenuitems))) {
return '';
}else{
if (!empty($CFG->custommenuitems))
$custommenuitems .= $CFG->custommenuitems;
$custommenu = new custom_menu($custommenuitems, current_language());
return $this->render_custom_menu($custommenu);
}
}
// http://docs.moodle.org/dev/Extending_the_theme_custom_menu
protected function render_custom_menu(custom_menu $menu) {
global $CFG;
require_once($CFG->dirroot.'/course/lib.php');
//navigation mycourses is no supported since 2.4
if (isloggedin() && !isguestuser() &&
$mycourses = enrol_get_my_courses(NULL, 'visible DESC, fullname ASC')) {
$branchlabel = get_string('mycourses') ;
$branchurl = new moodle_url('/course/index.php');
$branchtitle = $branchlabel;
$branchsort = 8000 ;
$branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
foreach ($mycourses as $mycourse) {
$branch->add($mycourse->shortname, new moodle_url(
'/course/view.php',
array('id' => $mycourse->id)),
$mycourse->fullname
);
}
}
$course_id = $this->page->course->id;
if (isloggedin() && $course_id > 1) {
$branchlabel = get_string('grades');
$branchurl = new moodle_url('/grade/report/index.php?id='.$this->page->course->id);
$branchtitle = $branchlabel;
$branchsort = 9000;
$branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
}
//From boostrapbase
// TODO: eliminate this duplicated logic, it belongs in core, not
// here. See MDL-39565.
$addlangmenu = true;
$langs = get_string_manager()->get_list_of_translations();
if (
count($langs) < 2
or empty($CFG->langmenu)
or ($this->page->course != SITEID
and !empty($this->page->course->lang))) {
$addlangmenu = false;
}
if ($addlangmenu) {
$branchlabel = get_string('language');
$branchurl = new moodle_url('#');
$branch = $menu->add($branchlabel, $branchurl, $branchlabel, 10000);
foreach ($langs as $langtype => $langname) {
$branch->add($langname,
new moodle_url(
$this->page->url,
array('lang' => $langtype)
),
$langname
);
}
}
return parent::render_custom_menu($menu);
}
protected function render_custom_menu_item(custom_menu_item $menunode) {
$transmutedmenunode = new theme_archaius_transmuted_custom_menu_item($menunode);
return parent::render_custom_menu_item($transmutedmenunode);
}
}
I am finishing some edits on a drupal project that was done by another programmer (I have no contact with him). I'm a newbie and trying to find out how the Paging module works. There are no numbers of pages showing. I suppose the programmer added some custom module or something.
I found a file named "pager.php" in the project's own theme folder with this function, that is probably doing the pagination:
function _my_pager_link($page, $text, $class, $title) {
$query = array();
$query[] = drupal_query_string_encode(array(
'page' => implode(',', $page)), array());
$querystring = pager_get_querystring();
if ($querystring != '') {
$query[] = $querystring;
}
$attributes['title'] = $title;
$attributes['class'] = $class;
return l("<span>$text</span>", $_GET['q'], array('html' => TRUE,
'attributes' => $attributes,
'query' => count($query) ? implode('&', $query) : NULL));
}
function my_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 5) {
global $pager_page_array, $pager_total;
$curr = $pager_page_array[$element];
$total = $pager_total[$element];
$output = '';
if ($total > 1) {
$output .= '<div class="pager">';
if ($curr > 0) {
$page_new = pager_load_array($curr - 1, $element, $pager_page_array);
$output .= _my_pager_link($page_new, t('‹ previous'), 'pager-prev', t('Go to previous page'));
}
if ($curr < $total - 1) {
$page_new = pager_load_array($curr + 1, $element, $pager_page_array);
$output .= _my_pager_link($page_new, t('next ›'), 'pager-next', t('Go to next page'));
}
$output .= '<div class="cleaner"></div>';
$output .= '</div>';
}
return $output;
}
Now there is just 'previous page' and 'next page' on the web. I would like it to be like this
'previous page '... 2 3 4 ... 'next page'
How can I add the list of pages there?
Thank You
Copy and paste http://api.drupal.org/api/function/theme_pager/6
Add salt and voila!
You need to set the global values like so:
global $pager_page_array, $pager_total;
$pager_page_array[0] = $your_page_count_goes_here;
$pager_total[0] = $your_page_total_goes_here;
And then you can call theme('pager', ...) or any custom paging theme function that you may have.