Drupal Access to Admin panel Denied - drupal

Inserted new menu item in hook_menu. But the menu item is not reflected. So in module i added the statement as
function {module_name}_menu_alter(&$items) {
$items['archives/faculty_article'] = array(
'access callback'=>'archives_list_faculty_article',
'access arguments'=>array(1),
);
$items['archives/faculty_article']['access callback'] = 'user_access';
}
Problem raised
1. Not able to access admin panel
2. user warning: Table 'nodewords_custom' doesn't exist query: SELECT * FROM nodewords_custom ORDER BY weight ASC
How can I correct the problem.

Have you flushed your menu cache after creating your new menu entry in the hook_menu()? It's mandatory if you want your new menu entry to be evaluated.
About your code snippet in the hook_menu_alter(), you are not altering properly the menu item, either your rewrite the full attributes of the item (title, page callback, access callback etc) either you just override one attribute (such as what you did for the access callback).
If you want to override two attributes you have to do something like that:
$items['archives/faculty_article']['access callback'] = 'user_access';
$items['archives/faculty_article']['access arguments'] = array('view');
After implementing the hook_menu_alter() you also have to flush your caches.
That's for problem 1. For problem 2, it means that you didn't install nodewords correctly, try to disabling it, uninstalling it and then re-enabling it to try to fix the issue. It should recreate the table for you.

Related

Drupal 8: How to unpublish node when user clicked on Delete button

On my website, The user can add the content and edit the content. On the edit page, there is one delete button to delete the content but I want to use that button to just hide/unpublish the content from the user and the public.
I have tried the below code but it is deleting the content.
function test_entity_predelete(Drupal\Core\Entity\EntityInterface $entity) {
$nid = $entity->id();
$node =Node::load($nid);
$node->setPublished(FALSE);
$node->save();
}
You can try to overwrite action button using hook_form_alter().
$form['actions']['delete']
Instead standard action use your own.
Firstly, do not allow users to delete nodes - by the proper
permissions settings.
Secondly add Publish/Unpublish button or just
show users Publish checkbox on edit form and instruct them how to
use it and how it works.
Maybe combination of modules can be helpful:
https://www.drupal.org/project/publishcontent
https://www.drupal.org/project/view_unpublished
https://www.drupal.org/project/override_node_options

Qt Installer Framework: conditional action based on whether a component was selected for installation

Generally: I need a bool or other hook to determine whether a component has been selected for installation, so that my controlscript.qs (or component-specific installscript.qs) can take the appropriate action.
Specifcally: the Qt installer framework has several default pages for the user to click through. On Windows there is a StartMenuSelection page which allows the user to specify what group (if any) the shortcut to the application should go into in the Windows Start menu.
Start Menu group selection example
One of my components to be installed is an (optional) shortcut in the Start menu. If not selected for install, there will be no shortcut to the installed application in the start menu.
My issue is that the Start Menu group selection page shows up regardless of whether the user has asked for a shortcut in the Start menu. I know how to get rid of it in all cases. But not conditionally on whether a Start menu shortcut is actually being installed.
I have a control script with the following:
function Controller()
{
}
Controller.prototype.StartMenuDirectoryPageCallback = function()
{
// Get the current wizard page
var widget = gui.currentPageWidget();
if (widget != null) {
var component = installer.componentByName("startmenu"); // startmenu is the component name
//if (!component.isSelected){
//if (!component.isSelectedForInstallation){
if (!component.isInstalled){
// I only want this hidden if the user didn't want a start menu link
// Either of the below commands will skip the startMenuSelection page
installer.setDefaultPageVisible(QInstaller.StartMenuSelection, false);
//gui.clickButton(buttons.NextButton);
}
}
}
But this doesn't work. component.isSelected and component.isSelectedForInstallation always return false, and component.isInstalled always returns true, regardless of if the component was actually selected for installation. Maybe these are the wrong booleans to ask?
Or maybe this is the wrong approach? Essentially, I just need a hook to determine if a component is selected or not.
Just found this link:
https://github.com/danimo/qt-creator/blob/master/dist/installer/ifw/packages/org.qtproject.qtcreator.application/meta/installscript.qs
Here they use:
component.installed
The isInstalled is a function (http://doc.qt.io/qtinstallerframework/scripting-component.html#isInstalled-method) that's why probably it always returns true.
So probably component.isInstalled() would have worked as well...
Either, installationRequested() would be another possibility to use. This is probably set before actual installation.

How do you access the title (Node module element) field in Drupal 7?

I have a computed field in a Drupal 7 content type that is populated by my description (text) field:
$entity_field[0]['value'] = $entity->field_desciption['und'][0]['value'];
It works fine. I want to create another computed field that is populated by the title (Node module element) field.
I tried with the following lines, but they don't work.
$entity_field[0]['value'] = $entity->title['und'][0]['value'];
$entity_field[0]['value'] = $node->title;
How can I achieve this?
The node title is not a field; therefore, using $entity->title['und'][0]['value'] will not work. What you should use is $entity->title.
As side note, to get the value of a field, you should use field_get_items(), which takes care of the language set for the field, which isn't necessarily LANGUAGE_NONE.
If it's a node module element, it should be accessible via $entity->title directly.
Try a print_r($entity); die; to get all elements of the entity. Hope this help you.
You should look at printing the array/object to the page to see what you are working with exactly.
Try adding print_r($entity); or print_r($node); to the page where the entity or node is displayed followed by exit;
You can then right click the page and click 'View page source' to display the output in a structured format. Use this to see the variable names, object/array types and hierachy to then write your full variable code correctly.
print_r($node);
exit;
I would imagine it should have been $node->title though...

get current page view in drupal

How to get the view of the current page in drupal.
I have a filter, whenever the user enters the search item, the view is changed.
$view = views_get_current_view();
does not work.
This worked for me :
$view = views_get_page_view();
Depending on the situation, the data should be in
$page_data = page_manager_get_current_page();
when called from MYTHEME_preprocess_page().
You may need to print_r the data, but I think the view name will be set as $page_data['handler']->subtask. I have used this in themes before, but depending on how your site is put together, this may not always work.

Drupal html user id

I'm using Drupal 6.16: I think I have a pretty simple question. How can I get the current user id and put it in a menu tab. What I would like to happen is when the user logs in and wants to change their name, email etc to click a menu tab. I image it would look something like this: http://domain.com/user/{userid}/edit
Thanks in advance!
msindle
That's more difficult than you would think, because menu items are cached. There is not a straightforward way to create dynamic menu items with the userID in it.
What you can do, is write a custom module and imitate the behavior of the 'user' path. With an implementation of hook_menu you create a menu item, with the path 'user/edit' (just like user_menu() creates $items['user']). Next you create a menu callback user_edit_page(), similar to user_page(), which gets the id of the current user and returns the user edit page:
function user_edit_page() {
global $user;
if ($user->uid) {
menu_set_active_item('user/'. $user->uid .'/edit');
return menu_execute_active_handler();
}
else {
return drupal_get_form('user_login');
}
}

Resources