How to make an administration page in Drupal? Is it even possible? - php

Let's say I'm making a blog in Drupal 7, and I want my end user to see a link: "Add Post", and when he clicks on that link he can add a new content. But instead of the default administration page, is it possible to create a new one, which has just the post title, tags, message and etc?
I've been searching for 2 days now, founding nothing about where to start/how to start a specific administration page instead of the default one.

You will have to create a specific module for that which will:
define the blog post editing form you want to have
define a page through a hook_menu function that includes the form
define a menu entry for it in the administrative menu
etc.
You should really get a little more into extending drupal by reading some pro drupal 7 book.
At least start reading http://drupal.org/node/1074360
Another very good starting point is the drupal "examples" module, which provides example code for most things your modules need to do:
http://drupal.org/project/examples

You could probably do all you need to by adding a template for the blog posting page to your theme. This lets you customise the display of the form, without needing to get too deep into Drupal programming.
Alternatively, you could create a module to replace the default blog submission form with one if your own design.
The theming and module design guides on the Drupal website give lits if detail on both these approaches.
James

you can have a different theme for management section, you can have multiple permissions depending on role, you can customize any page using ***node.tpl

Every add/content_type is a form. Forms can be altered with hook_form_alter or hook_form_id_alter.
If you want to have different fields that are shown for different roles, first see if it could be done on the admin/people/permissions page, if not write extra if conditions inside the form_alter.
e.g. check user role:
global $user;
// Check to see if $user doesn't have the administrator role.
if (!in_array('administrator', array_values($user->roles))) {
// Alter the form
}
You can check the form variables with dpm($form) when the Devel modules is enabled.

Related

What is the best way to create page in Drupal 8 so that I can then add these posts with images?

I have a Home page on the Drupal website (such as is created after installation), but I still need to create this page:
What is the best way to create a page so that I can then add these posts with images?
I am just starting to learn Drupal and have heard so far about such ways of creating pages:
1) in admin toolbar: Content / Add Content / Article
2) in admin toolbar: Content / Add Content / Basic page
3) in admin toolbar: Structure / Views / Add Views
Which one should I use? Or maybe there is some other option that I don’t know about?
P.S. At the moment I am more interested how to create empty page on which I can then add posts later, and adding posts it is another question.
Welcome to Drupal.
Drupal ships with the default theme which won't look nice but it does its job in the right way. Now if you want to create a better UI/UX obviously you should create a new theme. But before that make sure to read and understand the concepts behind Drupal. Drupal docs are your first friend.
Drupal Documentation
Drupal considers everything as nodes and that's how Drupal got its power. As you mentioned, Articles, Basic Page etc are called content types and they can be used to create a particular type of content.
Now for your purpose create a new content type and add the fields you need. From the image above I can say your content type needs Title, Image, Category and Date. After creating content type you can create as many contents as you want under the content type you just created. Consider each card in your image as content.
Now you can use a Drupal Core Module Views, to perform DataBase Operations without writing single code. Yes, you can select fields, sort, order etc with Views UI and display it in a page or a part of a page (Block).
I would say just try this out in the default Drupal theme and when you understand how this works, you can start creating your own theme for your project.
Theming Drupal
There is a lot of resources available. But you have to make sure what you are asking is whether you actually need. It will take some time, but it worth.
To build layouts for homepages on Drupal 8 you best friend is https://www.drupal.org/docs/8/core/modules/layout-builder
To build the content blocks inside your home page, you should start creating nodes on a node content type to hold your information. For instance: news content type, with a title, a body, a date, and an image.
For every node type, ex. news, work on the preview display, full display, and any other display which makes sense. These displays can be used later in the Layout Builder directly or in Views, referenced below.
If you wish your list to be dynamic, such as the last 10 entries are shown first, then use a view to hold the content sorted and filtered as you need.
In a nutshell.
Create a content type for your article/news.
Modify the displays of the content types to have at least a summary and full view.
Create the content itself to have something to see.
Create the view (block) to filter and sort your content.
Create a page layout (this makes sense for landing pages) which places your new view and any other content you need in any disposition.
This is roughly what I would do. The steps described above contain many intermediate steps. If in doubt, check the docs.
I hope that helps!
First, decide what will you display on that page. Is it content in some existing content type (article maybe) or you want to crate new one for this purpose.
If you need new one then create it (Structure -> Content types -> Add content type).
Then check what fields will you need. I.e. image, some description text. Add missing ones.
Create few nodes (pages) in that type so you could work with them.
Then for displaying you should crate a view (Structure -> Views -> Add view). It can be a page view (you are displaying only that content on page) or block view (this is just a block among some others). If you create a page you could visit it and if you create a block you have to add it to some region to appear on page (Structure -> Block Layout).
Inside your theme you should create templates for this page/block. Turn on twig debug mode so it will show you hints - what templates are used and how can you name yours to override default ones.
Adjust CSS to make it look like you want it to look.
Find some tutorial(s) for the details
Previous answers have given the flow of the work you should go through, I would like to add some resource that might help you achieve this.
Creating content type and fields: https://www.drupal.org/docs/administering-a-drupal-site/managing-content-0/working-with-content-types-and-fields
https://www.drupal.org/docs/user_guide/en/structure-content-type.html
View and View modes: https://www.drupal.org/docs/user_guide/en/views-concept.html
https://www.drupal.org/docs/8/api/entity-api/display-modes-view-modes-and-form-modes
Handling block of the view: https://www.drupal.org/docs/8/core/modules/block/overview
Feel free to ask if any further explanation is needed.
Thank you

Where to find a list of pages automatically renderable in Drupal and how it works?

In the pages .tpl.php of my theme i can find several lines like
render($action_links)
displaying whole pages with a single command. Sometime i saw that the render argument is a block from my theme .info, but other times i see arguments i cannot identify that render default pages or elements of drupal.
How it works? And where i can find a list of default displayable pages?
In particular, i needed to display the content of the default drupal page "add content" in one of my pages, and i'm pretty sure i can do it using this render method, but i cannot find the correct argument.
EDIT: I found something like
drupal_render(node_add('NODE_TYPE'));
that seems to allow the display of a node add form, but what i need is the main add content page, containing the list of all the type of nodes that a user can add.
Are you new to Drupal? When I read your post, I'm almost sure that you have missed something with the Drupal's working. The variables you found in render() functions are "calculated" somewhere else in the code (in the modules part for the most).
You cannot find a list of constant variables to display them just like this.
I found this article about these mysterious variables that are rendered and I hope it will help: http://newsignature.com/articles/the-magic-behind-drupals-render-elements
If you just want to display the "add content" form somewhere on your site, just call its path (node/add).
EDIT AFTER CLARIFICATIONS:
First of all, you can set on which page you want the user lands after login. (I don't know why you're still talking about user profile template. Maybe I missed something again.)
But if I did understand what you're trying to achieve, I'll do that:
Create a menu (or simply use the "Navigation" menu that seems to be exactly what you need) with all the actions users can do. And I'll place this menu in the main content region. Do create a menu, go to Administration>Structure>Menus>Add menu. And add links like "node/add/article" or "node/add/news" or "node/add/page" or whatever your content-types are.
Place this menu in the region you want. If you want it to be like the main content of the page, place it in the main container. To do so, go to Administration>Structure>Blocks> Drag and drop your menu in the right region and Save.
Configure this block to appear only on the front page (the first page on user arrives after logged in) if you want so. To do so, in the Blocks administration page, click on "Configure" next to your block and check "show block on specific pages: Only the listed pages" and write down <front>
Create roles and permissions for your different sorts of users. That will automatically show them the links they are allowed to see. To set permissions, go to Administration>People>Permissions and check in the "Node" section which content-type each role can create.
I hope I didn't forget anything. Please tell me if it is clear enough.

Need to create a custom blank page in drupal

I've installed Drupal to have a basic user registration layer. Now I need to code some PHP code in a blank page, how I can achieve this in Drupal? I need to know where I must put my PHP code.
Thanks a lot
Edit.
Basically I need Drupal only for user authorization. After a user logged into the system I want to show him a table with some data. This table was managed with JQuery.
for what you want to do I think it's not necessary a custom module, but if so, it's not so hard to do, but you can allways use some existing drupal modules mixed together to do what you want.
You will need:
Display Suite and
Login Redirect module
Basically I need Drupal only for user authorization. After a user
logged into the system I want to show him a table with some data.
For this purpose you can use Login Redirect module to redirect user to any page you want.
Now I need to code some PHP code in a blank page, how I can achieve
this in Drupal? I need to know where I must put my PHP code.
For this you can use Display Suite. Display suite or simply DS comes with a new a new Text Format: "Display Suite code". This text format allow you to add some custom code to your pages (javascript,php,etc)
you should learn to develop Drupal modules
with hook_menu you can make page
and with hook_form_alter you can edit registration form
but in drupal 7 you can manage registration fields
and also with rules and views modules, you can manage registration and user list without PHP coding
You will have to create a module in order to add php code to drupal. Try this to understand better what u need to do https://drupal.org/node/1074360

Force K2 registration and profile views to be used instead of the default registration and profile views?

I converted a site from 1.7 to 2.5, and all is really just about done, but I'm having one issue. I want to use these two custom K2 templates that existed in the previous version for both user registration and user profile because they were using K2 as the user registration mechanism.
I've configured K2 to Enable K2 User Profile:
but for whatever reason, when I navigate to index.php?option=com_users&view=register it's still grabbing the default registration form. Now, I thought it was maybe the URL, but the old 1.7 system is using the same URL. So, with some debugging I found that when the layout is told to search for a file, the K2 path isn't in the array.
What did I do wrong here?
NOTE: I also tried configuring the User Manager so that Allow User Registration was set to No, but I just get a 403 then because it's just not overriding with that K2 template.
UPDATE
As I stated in the comments, for whatever reason I don't have a K2 registration menu item type. However, the weirdest part is that the 1.7 version didn't point to the K2 registration either.
A little more background. This is a really hacked together system. The menu is actually built with a Jumi module that is straight forward custom and when the user is logged in the link that is used for the profile for example is this:
index.php?option=com_users&view=user&layout=form&id=3
and the register link, which is also custom (i.e. it's a link on a custom view) is this:
index.php?option=com_user&view=register
So, in short, I don't know enough about the Joomla navigation system to understand how to get those links to reroute to the K2 views that reside /components/com_k2/templates folder.
UPDATE
I put the register.php view that existed in /components/com_k2/templates folder into the /templates/tmplname/html/com_users/register folder and renamed it default.php so that the default user registration navigation would choose that view. And it did choose that view, no real surprise, but it also failed on a line like this:
<?php if(count(array_filter($this->K2Plugins))): ?>
because K2Plugins is null and that's not allowed for the array_filter function. I'm guessing this is because if this view were inside the com_k2 folder, like its original location, this would be available. I'm trying everything I can think of now.
It also threw on this line:
$this->K2Params->get('recaptchaOnRegistration')
because K2Params is null so of course get isn't available.
I found the problem, finally! The /plugins/system/k2/k2.php was catching the onAfterDispatch method for the navigation of com_users. If it was com_users and register or profile then it redirected and leveraged a different view. Well, the problem was that the old code said com_user instead of com_users. Silly!

Restrict access to a webform node to only a particular role in Drupal

Im using Drupal 6.19 and have used the webform module in Drupal to create a form on my Drupal site.The form shows up in the navigation menu.
Is it possible to restrict access to the form to only a particular role ?.
That is, i want only users belonging to a particular role to be able to see the form link in the navigation menu and be able to access it.Users belonging to other roles should not see the form link in the navigation menu and also should not be able to access it.
Can this be done ?
Please help
Thank You
as always, there are several ways to skin a cat... :)
how about using the node privacy by role module? seems to do exactly what you are asking for. you can set it by content type or on a per-node basis, if you need control that granular.
other modules to look at at: content access and webform submission acl
hope that helps.
Probably you should check hook_access to do it manually. Or look at the content access module if it may help.

Categories