Drupal 8

"Warning: file_exists(): open_basedir restriction in effect" when trying to install new modules on Drupal 8.x

If you are using shared hosting, service provider may restrict the right to access the top-level directory.

1.Modify the function mkdir as following at "/core/lib/Drupal/Core/File/FileSystem.php"

How to change and update database using hook_update_N in Drupal 8

  1. Create *.install file inside your module folder. If your module is named mymodule, the path of the *.install file should be in "/module/mymodule/mymodule.install".
  2. Impletment the hook_update_N function on the mymodule.install file. The character N is the version number of the update.
    • In Drupal 8, The first digital should be 8.
    • The second digital is the api version of the module.
    • The last two digitals is the serial number of the update.

Create a popup form in Drupal 8

  1. Add a route record into /modules/my_module/my_module.routing.yml
    • This route indicated the function openForm of openFormController will be executed after you goto the url of http://yourdomain/openForm through browser.
        path: 'openForm'
          _controller: '\Drupal\my_module\Controller\openFormController::openForm'
          _title: 'Open Form'
         _permission: 'access content'

Programmatically create a custom block in Drupal 8

  1. It seems that we cannot create a custom block in existing modules on drupal 8. So you must create a new custom module first.
    • create a .info.yml file like so: /modules/custom_blocks/custom_blocks.info.yml
      name: All My Custom Blocks
      type: module
      description: Defines a custom block.
      core: 8.x
      package: Custom
        - block
  2. Create the following file /modules/custom_blocks/src/Plugin/Block/MyFirstBlock.php

How to add custom block region on drupal 8

  1. Open YourThemeName.info.yml file exists in /core/themes/YourThemeName/
    • Add the string "header1 : Header1" under the keyword regions:
      name: YourThemeName
      type: theme
      description: 'YourTheme'
      package: Core
      base theme: classy
      version: '1.0.0'
      core: '8.x'
      project: 'drupal'
      datestamp: 1502903957
        content: Content
        header: Header
        headline: Headline
        primary_menu: 'Primary menu'
        secondary_menu: 'Secondary menu'
        footer: Footer
        highlighted: Highlighted

Page redirect after form submit on drupal 8

  1. Find the route name and variable of the page that you want to do redirection on "modules/yourModule/yourModule.routing.yml"
    User.routename://<--route name
    path: 'your_page/{var1}/{var2}'//<--variables
       _controller: '\Drupal\yourModule\Controller\pageController::getPage'
       _title: 'My next page'
  2. Add this script on the function submitForm.
    public function submitForm(array &$form, FormStateInterface $form_state) {
         $url = \Drupal\Core\Url::fromRoute('User.routename',['var1'=>'value1','var2'=>'value2']); 

(Solved) "proc_open(): fork failed - Cannot allocate memory"

Cause by:

Not enough swap space in the running server.


  1. Create new swap
    /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
    chmod 600 /var/swap.1
    /sbin/mkswap /var/swap.1
    /sbin/swapon /var/swap.1
  2. Run your command again.
  3. Remove swap
    /sbin/swapoff /var/swap.1
    rm /var/swap.1


Subscribe to RSS - Drupal 8