Best practices to implement custom functionality on website - drupal

I was wondering if someone with Drupal experience could advice what are the best practices in the following situations. I think they are all common tasks for any website that you build.
Display a custom HTML of a certain content type at front-page (e.g., only the link and title).
Should I build a module only for this?
Customize the login form HMTL, including inputs, labels etc, to something very different from the default login block.
Again, another module?
Format the node view of some content types; for example: showing additional fields values. I have some Joomla experience and with it, it's very easy to override the template on your theme.
But with Drupal, it seems HTML is hard-coded on PHP files and there are very few thing that uses templates. Or am I missing something?

You should create a view (from Views module), and for this create display 'block'. This block you can use later on your site. Within your view settings you can choose what and how you will display.
It depends what you would like to put there. If you put just some static text, change theme could be a solution. But still, a bit smelly. What you should do, is to create a module use hook_form_FORM_ID_alter and add both - field to your form, and code to use values which user added.
Change templates for this content type in your custom theme; or use Panels module - here you have nice introduction; or use Display Suite module - which do pretty much the some work as creating a template

html is in php files, but where else can it go? Drupal also has it template overwrite system. The customization of the theme can be usually done using that alone.
As for your questions (there are also other alternative)
load the content type in view/block, display in list format on home page.
create your own theme for css changes. create custom tpl.php for
layout, and div naming etc.
same as above.
It doesn't hurt to create a new module, but generally it's not necessary unless you are going for something like a muti-step form.

You can use both Views & Panels in order to achieve what you've mentioned above.
For instance, Panels gives you the option to override the home page with your own content. This content can be organized with Views.
From drupal.org:
"The Views module provides a flexible method for Drupal site designers to control how lists and tables of content (nodes in Views 1, almost anything in Views 2) are presented."
"The Panels module allows a site administrator to create customized layouts for multiple uses. At its core it is a drag and drop content manager that lets you visually design a layout and place content within that layout."

Related

What's the best Wordpress page builder for creating custom HTML blocks and controls?

I'm searching a most simple solution to create my own page builder system. I want to code my own blocks and then add to them some controls, only that what I choose.
So on firs fire goes ACF with ACF Extended. Works great until I didn't create more flexible fields. For example, I'm creating ROW (first flexible content) with a specified numbers of columns. Then, in each column I'm adding a BLOCK (second flexible content). Some of the blocks can contains other flexibles or repeaters. In ACF the problem is a lot of flexible and repeater fields. If is to much of them, then WP admin crash, data is saving, but sometimes only a partial.
So I'm searching other, lighter solution for that. I've tried I think every page builder like Elementor, WP Backery, Beaver. Problem is they are based on build-in elements and a lot of controllers. It's fine if someone want's to create site quickly, without coding. But I need a some kind of developer environment when I have control on each function of my HTML blocks.
So, is anyone knows what tool I could use for that?
Thaks!
You did not name it in your list, so what about the Gutenberg Editor?
It's already in the core of wordpress, so the wordpress developers thought, this is the best block editor.
You can easily create your custom blocks and controls with ACF:
https://www.advancedcustomfields.com/resources/blocks/
This may also help:
https://www.advancedcustomfields.com/blog/acf-5-8-introducing-acf-blocks-for-gutenberg/
With Gutenberg, you can be sure, this is not an editor which will be gone in a few years. It will stay in wordpress core and it is only in the beginning of becoming the best WYSIWYG Editor in the core of a cms.

Drupal 7: best way to render arbitrary content directly into <body> while keeping what's in <head>

I'm new to Drupal. As I understand a Drupal(7 in my case) page normally would have layers of wrappers around a block, sections, regions etc ... What I'm trying to achieve is to render some arbitrary content directly into "body" with none of the wrapper overheads, while keeping everything in "head". I've researched hook_block_list_alter which allows you to exclude blocks before rendering - which doesn't offer the ability to customize (removing) sections. Then I came across hook_page_alter looks like a good way to go, although I haven't dug too deep yet, still trying to understand the structure of the $page object. I thought about other options such as using the context module to configure sections/zones when requested page url is in certain pattern.
What's "THE Drupal's way" of doing this?
I would suggest you to first try with Drupal's template system and then, if you can't achieve something try with hooks:
https://www.drupal.org/node/337173
So, as you mentioned drupal has layer templates wrapping one around another. Most outer one is html.tpl.php and if you want something to appear in page head put it there. Then, second inner one is page template, which can be different for any content (node) type. But you also have block templates, field templates...
To override templates for specific content type or field or something else Drupal has some special naming convention. So if you name you template some specific way (and clear the cache!) drupal will start use it in that specific case.
Check the documentation for more details.

Is there any reason I shouldn't make pages folderish

I find the hardest thing to explain to Plone end users is the concept of having to make a folder, a page and set the folder's default view to a page in order to have nested pages. Is there any reason I shouldn't include a folderish version of a page content type in my product?
there are existing products that provide folderish types that almost behave like pages for the end-user
eg. Products.Richdocument and raptus.article.
personally i prefere raptus.article because of it's concept of components. editors can activate carousels, or image galleries and define which of the contained images are displayed in which component.
in many project i also define custom components eg one for showing addthis integration under the article text if editors turn on the component.
Ulrich Schwarz is right when commenting that using folderish content types as pages brings in extra complexity when it comes to versioning.
the problems in versioning with cmfeditions could most likle be solved by using attributestorage instead of annotationstorage for archetypes fields. (see https://dev.plone.org/ticket/11887)
The simplest was is to compare Plone as a filesystem.
There are discussions/rumors about making all content types folderish, but right now I suggest you to to something folderish only when really needed. The UI of a folderish content is more complex
Keul is right. Compare Plone as a filesystem.
I think also that you don't always have to set a page as the default view of a folder, sometimes you just want to have a list of contents (files, images, pages, etc...).

Drupal - Show content on specific page

Am I able to add the following field to a content type, so that each piece of content I create can be conditioned to a page?
Or is there a module to extend Publishing Options, where by it adds all the pages I have created (just like 'Promote to Front Page')?
If not, why is no one doing this? As a new user to Drupal this seems like it would be a handy operation. (I have already tried this module but it doesn't achieve the results I'm after).
If none of these solutions are available, what would be the best alternative way of doing this?
I've posted this question on Stack Exchange for Drupal but I need a quick answer and there seems to be a bigger community here :D
You should use Context. With Context, you'll be able to manage contextual conditions and reactions for your drupal like Regions.
Have you used Views? it is one of the most common used drupal modules. It doesn't extend publishing options directly but it does replace it in a way. You can say by example put a list of al content-types: your_own_Content_type that have the publishing options of promoted to front-page. then sort them by title, date, what ever you like.
you could also create only one view and create multiple blocks out of it. you have to understand the logic of drupal: if you want different blocks on different pages, you have to create the different pages AND different blocks
create the view for one type of content-type and make one block out of it. put this block on the desired page. All your other blocks are made with the same view, just adjust a condition in your view and create a new block out of it. You should also put all your blocks in the same region, and set the to the right pages
here you can find a lot of documentation if you run into any problems... drupal.org/project/views
Views is the best at creating a slideshow of images or any type of data on your site.
Used in combination with nodequeue it might offer near or the full functionality you are trying to achieve (check this out ... and this too) - but I don't understand your question entirely.
By my opinion Views is too complicated task for much simple request.
There is a few ideas for solution:
Easy way - You can create a specific template file or add some if statments to the node.tpl.php(specific tpl better)
For minor changes - Create a new context with "path" filter and "theme html" reaction, than hide the field by the css
Best but complicated(large usages) - create a new "view mode" and implement the display by new "hook_menu".
~ Almog

How to theme a view in drupal

Can any one help me out on how to theme a view.
For each view created i want to have different templates.
Theming views can be somewhat tricky, depending on the kind of views you have created and the changes you need to make. Check out this introduction for Views 2, and make sure to install the Advanced Help module to get at the views2 documentation from the views module itself (there will be a link to the documentation on your views overview and edit pages, once you activated the Advanced Help module).
You can also find some questions/answers here on SO (e.g. Drupal 6: How to quickly theme a view?), if you search a bit.
I actually did this the other day. Ill give you a brief overview and expand a little later.
Set up your view; by going to Views -> Add View
Once, your view is completely set up, at the bottom of the view (left column in D6, right-most "Advanced" column in D7), you will see a link called "Theme: Information", click on it.
What you will be presented with is a list of templates (.tpl.php) files that the views uses to theme your data. Basically the file names that are bolded are the files views is using to theme the data.
To Customize Your Views
Select the page you need to theme. For Example, if you created a "Block" view, and I wanted to customize the basic html layout, I would pick a name (other than the one that is currently bolded) that is being displayed to me and create the file in my themes directory (sites/all/zen/custom-file-view-fields-views.tpl.php) - this is if views told me that I could use the filename custom-file-view-fields-views.tpl.php
The next step is knowing what code you need to put in there. The quickest way, is to go back to the theming information in views, click on the link of the file your replacing and grab the code that is presented to you. Paste that code in the file you created.
From here on out, you can now successfully customize that view.
Keep in mind that the theming information presented to you is presented from basic to complex (up to down). So choose which file you need to edit carefully. Ill put up some images in this answer a little later.
Hope this helps! Cheers!
Is there something specific you're trying to accomplish? There's a lot of ways to "theme" a view, unless you mean "theme" in the strict Drupal sense.
Personally I just give the fields classes and use those, rewriting the output to include variables as classes if need be. This tends to be easier and more manageable than modifying TPL files directly.

Resources