I'm trying to develop a plugin in Moodle. One of the requirements is to add an element to the Settings Menu, in which I was able to achieve with the help of this guide
https://docs.moodle.org/dev/Local_plugins#Adding_an_element_to_the_settings_menu
And this is my code in local/myplugin/lib.php
<?php
function local_myplugin_extends_settings_navigation($settingsnav, $context) {
// question_extend_settings_navigation
global $CFG, $PAGE;
// Only add this settings item on non-site course pages.
if (!$PAGE->course or $PAGE->course->id == 1) {
return;
}
// Only let users with the appropriate capability see this settings item.
/*if (!has_capability('moodle/backup:backupcourse', context_course::instance($PAGE->course->id))) {
return;
}*/
if ($settingnode = $settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) {
$strfoo = get_string('classrecord', 'local_myplugin');
$url = new moodle_url('/course/classrecord.php', array('id' => $PAGE->course->id));
$foonode = navigation_node::create(
$strfoo,
$url,
navigation_node::NODETYPE_LEAF,
'myplugin',
'myplugin',
new pix_icon('i/grades', $strfoo)
);
if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
$foonode->make_active();
}
$settingnode->add_node($foonode);
}
}
?>
I allowed the students to see the element "Class Record" in the settings menu
My concern is that how can I hide/show Class Record I added?
Any ideas would be great!
If you want only certain users to see the link, then create an appropriate capability in local/myplugin/db/access.php, e.g. 'local/myplugin:viewclassrecord', defaulting to being assigned to the 'student' role. Then check for it in the function you have defined.
e.g.
if (!has_capability('local/myplugin:viewclassrecord', $context)) {
return;
}
Related
I'm trying to auto publish child pages if they are rearrange. Right now when we arrange those child pages it says modified.
We're trying to achieve an automation on how to auto publish it once we started drag and drop to their position.
The idea may be to check the change of the Sort field and execute the doPublish(). Please, note that you must check if the page wasn't in the Draft state.
class FooPage extends Page {
private $wasPublishedBeforeWrite = false;
protected function onBeforeWrite()
{
parent::onBeforeWrite();
// check if the page is published
$this->wasPublishedBeforeWrite = !$this->isArchived() && !$this->isOnDraftOnly() && !$this->isModifiedOnDraft();
}
protected function onAfterWrite()
{
parent::onAfterWrite();
if ($this->isChanged('Sort') && $this->wasPublishedBeforeWrite) {
$this->publishSingle();
}
}
}
On the shop page I have...
Product Categories
All Products
Education
Instructor Store
When a customer logs into the store, I would like 'Instructor Store' to change to 'Training'. The slug can stay the same, just need the category name in the HTML to change. Is that possible?
I prefer to add something to the functions.php file versus installing yet another plugin. Any help would be appreciated.
You can add a small function to check if a user has a role and call it from your php template to decide what to show him. Something like this:
function my_has_role($user, $role) {
$roles = $user->roles;
return in_array($role, (array) $roles);
}
This can go into your functions.php and then you can call it anywhere for a specific or current user:
$user = wp_get_current_user();
if(my_has_role($user, 'Customer')) {
//do what you want here
}
A similar function, if you always want to check current logged in user, would be this:
function my_current_user_role($role) {
if( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
return in_array($role, $roles);
} else {
return false;
}
}
/* Use it like this */
if(my_current_user_role('Customer')) {
//do what you want here
}
Could you please tell me how to publish pages after clicking edit button (left top menu) mode in cocrete5 cms version 5.8.1.0 not using compose button?
I can't publish any page clicking edit button in top left corner, editing it and clicking edit button again.
Publish Changes Button is disabled and there is message:
"The field Page Thumbnail is required."
But I can publish using compose menu (next to edit in left top corner).
What's the cause of this problem? Is it concrete5 bug?
It looks like it allows to publish if I comment out lines in check for publishinh method. But I can't still understand the cause of issue and how to fix it.
class CheckIn extends BackendInterfacePageController
{
protected $viewPath = '/panels/page/check_in';
// we need this extra because this controller gets called by another page
// and that page needs to know how to submit it.
protected $controllerActionPath = '/ccm/system/panels/page/check_in';
public function canAccess()
{
return $this->permissions->canApprovePageVersions() || $this->permissions->canEditPageContents();
}
public function on_start()
{
parent::on_start();
if ($this->page) {
$v = CollectionVersion::get($this->page, "RECENT");
$this->set('publishDate', $v->getPublishDate());
$this->set('publishErrors', $this->checkForPublishing());
}
}
protected function checkForPublishing()
{
$c = $this->page;
// verify this page type has all the items necessary to be approved.
$e = Loader::helper('validation/error');
if ($c->isPageDraft()) {
if (!$c->getPageDraftTargetParentPageID()) {
$e->add(t('You haven\'t chosen where to publish this page.'));
}
}
$pagetype = $c->getPageTypeObject();
// if (is_object($pagetype)) {
// $validator = $pagetype->getPageTypeValidatorObject();
// $e->add($validator->validatePublishDraftRequest($c));
// }
if ($c->isPageDraft() && !$e->has()) {
$targetParentID = $c->getPageDraftTargetParentPageID();
if ($targetParentID) {
$tp = Page::getByID($targetParentID, 'ACTIVE');
$pp = new Permissions($tp);
if (!is_object($tp) || $tp->isError()) {
$e->add(t('Invalid target page.'));
} else {
if (!$pp->canAddSubCollection($pagetype)) {
$e->add(
t(
'You do not have permissions to add a page of this type in the selected location.'
)
);
}
}
}
}
return $e;
}
The error says it all? 'The field Page Thumbnail is required.' Did you actually add a thumbnail?
Basically you can't submit a form without filling in all the required fields.
Or did you and still got the error?
I could solve the issue overriding file:
<?php
namespace Application\Attribute\ImageFile;
use Loader;
use Core;
class Controller extends \Concrete\Attribute\ImageFile\Controller
{
public function validateValue()
{
$f = $this->getAttributeValue()->getValue();
if (is_object($f)) {
return true;
}
$e = Core::make('helper/validation/error');
$e->add(t('You must specify a valid file for %s', $this->attributeKey->getAttributeKeyDisplayName()));
return $e;
}
}
I have put a "Global:link" in the header of a view in Drupal 7. I suppose I could put the link as html in a Global:text area as well.
If the user is not admin I don't want them to see this link. So I have tried to put this code in my themes template.php:
// hide global text area in view header if user is not admin
function mytheme_views_pre_render(&$view) {
if ($view->name == 'taxonomy_term') {
dpm($view->name);
global $user;
// Check to see if $user has the administrator role or not.
if (!in_array('administrator', array_values($user->roles))) {
$header_item = $view->display_handler->get_option('header');
dpm($header_item['link']);
unset($header_item['link']);
}
}
}
}
.. but how do I unset a global field in the header of this specific view?
My code above does not do the trick.
Any help would be much appreciated!
SOLVED. I finally solved it. Here's the snippet. Hope it helps somebody having the same issue. Change "link" to whatever item you use in the header:
function mytheme_views_pre_view(&$view, &$display_id, &$args) {
if ($view->name == 'taxonomy_term') {
global $user;
$new_item = $view->get_item('page', 'header', 'link');
$new_item['text'] = "";
// Check to see if $user has the administrator role or not.
if (!in_array('administrator', array_values($user->roles))) {
$view->set_item('page', 'header', 'link', $new_item);
}
}
I've got a MediaWiki site and I would like to add a tab with a very simple "read article" functionality (without any edit/comment options). I followed the manual and tried to create a namespace for it, but it still doesn't work.
The snippet from LocalSettings.php looks like this:
define("NS_ARTICLE", 500);
$wgExtraNamespaces[NS_ARTICLE] = "Article";
$wgNamespaceProtection[NS_ARTICLE] = array( '' );
$wgNamespacesWithSubpages[NS_ARTICLE] = true;
$wgContentNamespaces[] = NS_ARTICLE;
I created new methods in Title.php:
public function getReadPage() {
return Title::makeTitle( MWNamespace::getRead( NS_ARTICLE ), $this->getDBkey() );
}
In Namespace.php:
public static function getRead( $index ) {
self::isMethodValidFor( $index, __METHOD__ );
return self::isTalk( $index )
? $index
: $index + 1;
}
And in SkinTemplate.php:
$readPage = $title->getReadPage();
$content_navigation['namespaces']['article']['class'] = 'selected';
$content_navigation['namespaces']['article']['text'] = 'Article';
$content_navigation['namespaces']['article']['href'] = $readPage;
$content_navigation['namespaces']['article']['primary'] = true;
$content_navigation['namespaces']['article']['context'] = 'subject';
The Tab appeared, but it links to ":Title" instead of "Article:Title". If I look for "Article:Title" page, the following message appears:
There is currently no text in this page. You can search for this page title in other pages, search the related logs, or edit this page.
Any ideas?
Don't touch the MediaWiki sources or you'll have to redo the same thing each time you upgrade. Tab manipulation is doable with hooks, e.g. SkinTemplateNavigation.