Variable CSS pour la hauteur de la barre d’outils d’administration : --drupal-displace-offset-top
Cette variable se met à jour automatiquement grâce au script JS displace.js intégré nativement dans Drupal.
On pourra par exemple utiliser cette valeur pour décaler des éléments pour les éléments ancrés qu’on accède grâce au fragment d’URL (le dièse en fin d’URL). Par exemple :
/*
* Décaler pour que l'ancre HTML soit positionnée en bas
* de la barre d'admin et non pas derrière.
*/
margin-top: calc(-1 * var(--drupal-displace-offset-top));
padding-top: var(--drupal-displace-offset-top);
À noter qu’il existe également d’autres variables sur d’autres dimensions :
We want to add on a node page layout a block which uses a field from the currently rendered content (node).
We want this block to be translated the same as the currently rendered entity.
As a anonymous user, we want it to respect the published settings of the currently rendered entity.
As an admin, we want to be able to see this block if the content is unpublished.
We want to support cases when a content is not translated. The default Drupal behaviour is to use the default translation.
Configuration
Configuration screenshot.
Do not use Published (= Yes) setting.
Views will remove itself results on which you don’t have permission—unless you have disabled access checks in the Query settings parameter of the view. Also, as an admin, you will still be able to see the block if the content is unpublished.
Set Default translation (= True).
Views will retrieve the default translation, which is the default result when you attempt to go on a node page which has no translation.
Set Rendering Language to Interface text language selected for page.
Views will attempt to translate the content. If no content translation is found, default translation will be used.
Contextual filter set to Content: ID with Content ID from URL as default value.
Hide block if the view output is empty.
No need to keep this block if there is no output (or keep it if you need it anyway).
I am currently working on a website for a video game reviews project I have had with an old friend of mine (FuuDoh). Obviously, I have switched to Drupal to get a result quicker than what I would get with the PHP only solution I have been working on a few years ago (it was fun though).
One of the main problems I have came across while theming was to give a consistent look across various web browsers (and now devices—mobile and tablets were not as much a concern as nowadays). Bootstrap was not as popular as it is now and it saved a lot of my time for my current project. But it did not fix one of the other problems I am still experiencing today: scrollbars.
I hate how they cannot be themed natively. In an overflow: auto setting, they push all the content by their width when they appear, potentially changing the height of the content; which is not very elegant in my opinion. You cannot change their size, nor their color.
With the big grow in the recent years in the JS scene, we have now good enough JS libraries which gives developers means to achieve better, cross-browser, cross-platform scrollbars.
I have checked a Drupal 8 module, scrollbar, which unfortunately does not work well (or was misconfigured). The bars were not refreshing when the browser window is resized. Maybe I’ll post an issue on the Drupal module tracker, but it does not seem to be the fault of the module. But there was one big drawback with the library used by this module (jScrollPane): the scroll behaviour is not the native browser’s scroll behaviour. You will not get any ease in the scroll animation (or maybe you could have it by configuring the library).
Then I have searched a little and found two candidates:
Both are JS libraries which use native browser’s capabilities to scroll the content; you will not feel anything different between normal scrollbars and those custom ones, which is perfect! The first library is currently (May 2018) used on Twitch.tv. I have not tested it, but it claims to be cross browser. But it also claims that there may be some performance impact when used on the body element. That is why I chose OverlayScrollbars, which is recommended by simplebar in its documentation by the way.
Relieved.
After having spent some time trying to figure out why it did not work, I have finally got it working nicely with the bootstrap+sass theme! The implementation is in fact trivial for a Drupal themer but here are the steps to achieve it.
Steps
Download the OverlayScrollbars library (link to releases) and extract the files to the themes/custom/THEMENAME/libraries/OverlayScrollbars directory (create necessary directories). This OverlayScrollbars folder must contain the css and js directories which came from the zip (remove any wrapping directory).
Create a file named trigger.js at this location: themes/custom/THEMENAME/js/overlayscrollbars/trigger.js
Add this to the file:
(function ($) {
//The passed argument has to be at least a empty object or a object with your desired options
$('body').overlayScrollbars({ });
// .overlayScrollbars({ }) must be appended on any single element you want a scrollbar.
$('nav.article-list').overlayScrollbars({ });
}(jQuery));
The THEMENAME.libraries.yml of your subtheme may look like this (the overlayscrollbars is what we care about):
When using Search API Page, I needed to theme the search form in the bootstrap structure. The cleanest answer I have found is to add some variables to trigger the bootstrap overrides on the search form.
/**
* Implements hook_form_FORM_ID_alter().
*/
function MYMODULE_form_search_api_page_block_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// We need this to make our search_api_page_block_form rendered in the bootstrap fashion
// This code was inspired by \Drupal\bootstrap\Plugin\Form\SearchBlockForm
$form['actions']['submit']['#icon_only'] = true;
$form['keys']['#input_group_button'] = true;
}
Additional Information
Instructions made on Drupal 8.3.x (probably, haha).
I am just dropping a note here about the basic steps of how to install XDebug for a specific setup.
Here is my configuration:
host:
OS: Windows 7 64 bits
IP: 192.168.0.3
IDE: Netbeans 8.2
guest:
OS: Debian Jessie 64 bits in VirtualBox
IP: 192.168.0.4 (bridged network in VirtualBox settings)
standard Apache2, PHP 5, MySQL from official repositories
The idea is: I want to use the stepper on a website located inside a virtual machine from an IDE on the host machine.
Step by step
XDebug installation
On the guest machine, get the phpinfo() output. If you have no idea how to do this quickly:
From the command line, run php --info > ~/tempphpinfo.txt (you can safely delete this file later).
Open the file: gedit ~/tempphpinfo.txt.
Copy all the contents.
Go to https://xdebug.org/wizard.php and follow the instructions: you will have to paste the contents of the phpinfo obtained earlier. The wizard will tell you exactly how to build xdebug. Make sure you are in the correct folder when running the phpize command.
Locate the xdebug.ini files (named 20-xdebug.ini on my Debian) on the guest machine:
cd /etc/php5
find | grep xdebug
Edit one of the files listed by the last command and add those lines:
;zend_extension=[path to xdebug .so/.dll]
zend_extension=/usr/lib/php5/20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
sudo service apache2 restart, just in case.
Testing XDebug
We will create a small php file which will react to XDebug calls.
Create a php file:
touch ~/testxdebug.php
gedit ~/testxdebug.php
Insert the following:
Save and close.
Start the command line debugger: php ~/testxdebug.php. You may have a warning about the xdebug extension already started: you can ignore it or fix this later by commenting/removing the zend_extension=path/to/xdebug.so line you have added to the /etc/php5/cli/php.ini file (not the xdebug.ini files!).
In the web browser, go to your website location, a Drupal 8 in my case and add an attribute at the end of the URL, e.g.: http://localhost/DrupalXDebug/web/index.php?XDEBUG_SESSION_START=mysession.
In the terminal where you have run the php ~/testxdebug.php command, you should see a message like this one:
connection established: Resource id #5
If not, the configuration is wrong and check the steps again or the resources links at the end of this article.
Setup remote debugging
Until now, we have only ran the debugger (the little php script we have created earlier, which you can safely delete now) from inside the guest machine. We will configure xdebug to work with remote machines, in my case, the Windows host.
Edit one of the xdebug.ini files you have edited earlier: replace the xdebug.remote_host value by the IP of the host, 192.168.0.3 in my case.
sudo service apache2 restart, just in case.
Netbeans configuration
Now we can configure Netbeans to run the debugger.
Open the website project.
Right click on the project in the Projects list and click on Properties.
Enter the URL of your website in Run Configuration > Project URL. In my case, it was like this:Where to set the website URL
Click on the Advanced button.
Set the path mappings. In my case:How to set path mappings
You should now be set for debugging with the stepper!
Run the debug
Click on the Debug Project button in the top toolbar of Netbeans and it should launch automatically a browser with a session id already set!
Put a breakpoint somewhere in the code.
Each time a request is sent to the website, Netbeans will control the page generation.
The path mapper functionality of Netbeans is required because the paths to the same resource (web page, php file, etc) are different between the host and the guest. As XDebug only knows about the guest path, e.g.: /var/www/html/path/to/site/file.php, Netbeans has to map it to the host path, e.g.: W:\path\to\site\file.php to be able to step through it. However, if you are not using remote debugging and therefore the server runs in local —and, if you are on Linux, you are not using symlinks— there is no need for path mapping.
This article is about the default admin_page, admin_block and admin_block_content templates which serves as the base of the content display on some system configuration pages such as the one on this image:Screenshot of the configuration page on a Drupal 8 website
The code
'admin_page',
'#blocks' => [
// Array of admin_block
[
'title' => $this->t('A block, on the left'),
'position' => 'left',
'content' => [
'#theme' => 'admin_block_content',
'#content' => [
[
'title' => 'Do something',
'url' => Url::fromRoute('your_module.some.example.route'),
'description' => $this->t('This will link to a route.')
],
[
'title' => 'Navigate to a nice blog',
'url' => Url::fromUri('https://blog.dakwamine.fr'),
'description' => $this->t('This will link to a URI, external in this case.')
],
[
'title' => 'Go to contents page',
'url' => Url::fromUri('internal:/admin/content'),
'description' => $this->t('Also works for internal URI.')
]
]
]
],
[
'title' => $this->t('Another block, on the right'),
'position' => 'right',
'content' => [
'#theme' => 'admin_block_content',
'#content' => [
[
'title' => 'Another link to a route',
'url' => Url::fromRoute('your_module.another.route'),
'description' => $this->t('Yup.')
],
[
'title' => 'Website example link',
'url' => Url::fromUri('https://website.example'),
'description' => $this->t('Goes on website.example.')
],
]
]
]
],
];
// admin_block style (full width)
$mainRenderArray[] = [
'#theme' => 'admin_block',
'#block' => [
'title' => $this->t('Full width block'),
'content' => [
'#theme' => 'admin_block_content',
'#content' => [
[
'title' => 'Another link',
'url' => Url::fromUri('internal:/admin/people'),
'description' => $this->t('A link to the people page.')
],
[
'title' => 'Another link again',
'url' => Url::fromUri('https://website.example'),
'description' => $this->t('Goes on website.example.')
],
]
],
],
];
return $mainRenderArray;
}
}
Explanation
If you use admin_page, you will be able to define the column in which the blocks dwell: left or right.
If you use directly admin_block, there is only a single block and it will span over the full width of the region.
So all in all, here is a pseudo hierarchy to better understand how it works:
I just switched my website to https for testing purpose. But changing the website’s URL to https:// is not sufficient to enable a fully secure browsing experience, as images in posts are still loaded from http://. Or more precisely, most modern browsers (FF or Opera for instance) are now clever enough to guess that the current website is on https:// so its contents should also be loaded with the same protocol, but there may be a possibility that other less advanced browsers are not doing this smart guess.
There are two possibilities:
install and activate a plugin such as the SSL Insecure Content Fixer. It will replace on the fly the protocols to https. The advantage is that your contents are not edited in the database. The drawback is that your website may be a little slower. (sorry I don’t have metrics)
the other method is to replace the src="http:// references in the post_content field from the wp_posts table by src="https:// by using SQL. For example, in phpMyAdmin:
make a backup of the wp_posts table (or even better, your database)
execute this query:
UPDATE `wp_posts` SET post_content = REPLACE( post_content, ' src="http://', ' src="https://' ) WHERE 1;
hook_schema is one of those methods where you are happy to have a usable documentation on the api website. It is pretty much self-explanatory and you don’t have to look for hours on third parties websites to get some usable information. 🙂