0

In the settings.php file, I have the following line, to use a local service.yml.

$settings['container_yamls'][] = __DIR__ . '/services.yml';

I need to install the Redis module, which instructs to put the following line in the settings.php file.

$settings['container_yamls'][] = 'modules/redis/example.services.yml';

I'm not sure how the settings array works. I think that just adding that statement will overwrite the existing one.

I want to add the array item as suggested in the documentation for that module.

Should I use these lines?

$settings['container_yamls'][] = __DIR__ . '/services.yml';
$settings['container_yamls'][] = 'modules/redis/example.services.yml';

Or should I use these lines?

$settings['container_yamls'] = array(
  __DIR__ . '/services.yml',
  'modules/redis/example.services.yml',
);
1

The settings.php file already contains the following line.

$settings['container_yamls'][] = __DIR__ . '/services.yml';

It is much easier to add the following one at the bottom of the settings.php file.

$settings['container_yamls'][] = 'modules/redis/example.services.yml';

Since it is added on the bottom of the file, it is easier to find and remove it, in the case you decide not to use that module anymore. In this case, you just remove a single line, and Drupal doesn't use that module's services anymore.

Also, if you install another module that requires to add a similar line, you just need to add a $settings['container_yamls'][] which can be easily removed without touching the other lines.

Those are the only considerations I could make about which code snippet I would use. Otherwise, for PHP 5.5 (and Drupal), the following code snippets are perfectly equivalent.

$settings['container_yamls'][] = __DIR__ . '/services.yml';
$settings['container_yamls'][] = 'modules/redis/example.services.yml';
$settings['container_yamls'] = array(
  __DIR__ . '/services.yml',
  'modules/redis/example.services.yml',
);
$settings['container_yamls'] = [
  __DIR__ . '/services.yml',
  'modules/redis/example.services.yml',
];
0

The correct method is:

$settings['container_yamls'][] = __DIR__ . '/services.yml';
$settings['container_yamls'][] = 'modules/redis/example.services.yml';
  • This is not true; I could use the other code shown from the OP, if I were to initialize the array in a single place, and it would be correct too. There are other considerations to take, but correctness is not one of them. – kiamlaluno Jul 13 '16 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.