19 votes
Accepted

How do I create a role programmatically?

The problem is in the data array change name by label: $role = \Drupal\user\Entity\Role::create(array('id' => 'client', 'label' => 'Client')); $role->save(); Or you can use: //your data ...
Adrian Cid Almaguer's user avatar
17 votes
Accepted

Cannot install any theme

This is an nginx configuration issue and discussed intensely on this page Yet curiously no solid solution could be offered. Some guy on an other page proposed a solution. I applied that proposed ...
salihcenap's user avatar
16 votes
Accepted

Installation error with Composer

Please make sure your webserver (nginx/apache) is using the same PHP version as your cli one. For example, you may encounter this issue if your cli PHP version is PHP 7.1 and your webserver is using ...
Renrhaf's user avatar
  • 638
16 votes
Accepted

Notice: Trying to access array offset on value of type null in while installing drupal

I suspect you are installing Drupal (or at least trying to) on a server running PHP 7.4, which is not currently compatible with the latest version of Drupal (8.8). There is an issue on drupal.org ...
Menno van den Heuvel's user avatar
15 votes

Does drush need to be installed as root?

NOTE The issue described in the Question has now be fixed in the latest Drush version. No, Drush does not need to be installed as root. I've submitted Drush pull #2246 to update the current Drush ...
Christopher's user avatar
14 votes

Drush CC all returning "No Drupal site found, only 'drush' cache was cleared"

There are a few things you can do to help debug your drush. Here is what you can try: Debug output Use drush cc all -vvv This will provide you with some valuable information in terms of what Drush ...
JNP Web Developer's user avatar
14 votes
Accepted

Error when attempting to create sync directory

Nothing wrong with that. It is recommend to have the config folder outside of the public web folder; Drupal just doesn't have that. To keep the installation simple for non-experienced users, it puts ...
Berdir's user avatar
  • 83.1k
12 votes
Accepted

How to install with composer external library that drupal module depends on

You should be able to include this package via composer by adding some repository info. Add a package definition to your repositories section in your composer.json. The resulting repositories section ...
sonfd's user avatar
  • 7,871
10 votes

Does hook_install() get called before or after configuration yml files are loaded?

When Drupal install a module, first it installs the default configuration of the module, then it invokes its hook_install(). This is evident from ModuleInstaller::install(), which contains the ...
apaderno's user avatar
  • 97.4k
9 votes
Accepted

How to fix error 'This site can’t be reached' for a site installed on Amazon?

It's because by default port 22 (SSH) comes open in your EC2 security group, but port 80 (HTTP) is not open. You need to edit your security group. To get there, in your EC2 list, scroll all the way ...
No Sssweat's user avatar
  • 31.2k
9 votes
Accepted

How to set the default theme programmatically

The current advice is to set this via config: \Drupal::configFactory() ->getEditable('system.theme') ->set('default', $theme) ->save(); The previous method using ThemeHandlerInterface:...
Clive's user avatar
  • 167k
9 votes

Grant permission for custom role from hook_install programmatically

Try this: use Drupal\user\Entity\Role; function mymodule_install() { $role_object = Role::load('my custom role name'); $role_object->grantPermission('my custom permission name'); $...
Andy Lasda's user avatar
8 votes
Accepted

Truncate tables before uninstalling a module in Drupal 8

That's a known issue right now. There's no way right now to hook into that automatically. And it came up a few times already here too. See this question for example: Module uninstall dependencies ...
Berdir's user avatar
  • 83.1k
8 votes
Accepted

How to recreate the user_picture field?

Instead of importing configuration as suggested previously, you could as an alternative, programmatically re-create the field. Here is some code that does that. <?php use Drupal\field\Entity\...
Stefanos Petrakis's user avatar
8 votes
Accepted

How do I programmatically install a module?

Use "module_installer" service. $installer = \Drupal::service('module_installer'); // Or from the container. $installer = $container->get('module_installer'); // Install single module. $installer-...
voleger's user avatar
  • 950
8 votes
Accepted

Disabling module with config sync and removing with composer

You need two consecutive releases for stuff like that. First release: Your colleague uninstalls the module and commits the updated config. If you don't manage your site via config use hook_update_N ...
leymannx's user avatar
  • 18k
7 votes
Accepted

Does drush need to be installed as root?

Not sure exactly what's going on there but I can reproduce it using the installation instructions. The problem is related to the execution path (haven't looked any deeper). If you move out of the ...
Clive's user avatar
  • 167k
7 votes
Accepted

Managing module library dependencies with composer

New method using drupal-scaffold for greatest flexibility For Drupal 8.4.0 and greater using drush >9.0.0, drush make is deprecated and you should use a full-composer work flow as detailed in the ...
mradcliffe's user avatar
  • 5,917
7 votes

Drush CC all returning "No Drupal site found, only 'drush' cache was cleared"

Noting that your drush status output does give a valid root, site path, database user, and database name, that means that drush is finding a valid settings.php file with credentials in it and can read ...
eporama's user avatar
  • 206
7 votes
Accepted

Programmatically build module permission list

You can list all available permissions with PermissionHandler: $permissions = \Drupal::service('user.permissions')->getPermissions(); You'll find the module name in the provider property of the ...
4uk4's user avatar
  • 99.3k
7 votes

Install Drupal using composer

Checking https://packagist.org/packages/drupal/drupal for the versions available there is NO 7.x version. Drupal 7 has no composer.json for this to command to work. You can use one of the other 2 ...
Clemens Tolboom's user avatar
7 votes

Installation error with Composer

For Ubuntu 16.04 I had to run the following commands to adjust the PHP version used by Apache: sudo a2dismod php7.0 sudo a2enmod php7.2 sudo service apache2 restart
Juampy NR's user avatar
  • 425
6 votes

How to resolve 'Fields pending deletion' and force deletion of said field?

You could force field deletion using drush with the command: drush php-eval 'field_purge_batch(500);' or you could install devel module and go to /devel/php and run field_purge_batch(500);
Pravin Ajaaz's user avatar
  • 3,542
6 votes
Accepted

Drupal 8 Equivalent of Drupal 7's disabling a module without Uninstalling it

https://www.drupal.org/node/2225029 The long and the short of it is that you cant. This option is no longer available in Drupal and it was a conscious decision to remove the ability to disable a ...
bleen's user avatar
  • 1,500
6 votes

Bootstrap failing with Drush 9.1.0

I has this issue and found this to work: rm -Rf vendor/drush composer install Credit: https://github.com/drush-ops/drush/issues/2959#issuecomment-332054773 This deletes drush and uses the composer....
therobyouknow's user avatar
6 votes

How to install with composer external library that drupal module depends on

You can do this by using Asset Packagist. Add repository and installer-types, installer-paths to your composer.json "repositories": [ { "type": "composer", "url": "https://asset-...
Tomotsugu Kaneko's user avatar
6 votes

Cannot install Composer because it doesn't contain any .info.yml files

IMPORTANT EDIT (2020-04-28): You are trying to install this project: https://www.drupal.org/project/composer But that is not Composer -- it's a Drush extension for managing Composer. From the ...
hotwebmatter's user avatar
  • 2,102
5 votes

Problem installing in local "The translation server is offline"

Download this file : https://curl.haxx.se/ca/cacert.pem And add the path to the file in your php.ini : curl.cainfo="D:\wamp64\keys\cacert.pem"
Yann Choquet's user avatar
5 votes
Accepted

How do I install Drupal with a custom language?

Seems this works fine: $ drush si standard \ --db-url='mysql://[db_user]:[db_pass]@localhost/[db_name]' \ --account-name=joe --account-pass=mom \ --site-name=Example \ --site-mail=...
Andrea's user avatar
  • 1,267
5 votes

File Transfer failed, reason: Cannot create directory /var/www/html/modules

The chmod a+x isn't enough, the directory should have write permission for HTTP server user, so try: chmod 755 /var/www/html Prefix with sudo if it's necessary. or if you've already some files in ...
kenorb's user avatar
  • 14.2k

Only top scored, non community-wiki answers of a minimum length are eligible