Posts

Showing posts from 2018

Gitlab CI Drupal 8 example

https://guillaumeduveau.com/fr/drupal/8/integration-continue-gitlab-ci-ansible General concepts of running gitlab ci. 1. Install gitlab runner on a server You will be asked to give a url and a token You can take it from your account -> settings -> ci-cd -> Runners Gitlab will use this token to make a api call to run the runner. 2. Generate a private key  in the server and use that as a variable SSH_PRIVATE_KEY in your account -> settings -> ci-cd -> Variables

All about APIs in Drupal8

node/1?_format=json restfult services in D8 => provides config entity https://dev.acquia.com/blog/decoupling-drupal-8-core-core-rest-hal-and-setting-up-drupal-as-a-web-services-provider/29/03/2018/19311 https://wimleers.com/blog/restless-week   https://drupal.stackexchange.com/questions/201800/how-to-expose-paging-data-in-rest-export-views   <entitytype><bundle><uuid> Look for data attributer in the response jsonapi/node/article/?page[offset]=0&page[limit]=1 /jsonapi/view/view/ /jsonapi/view/view/<uuid> for search_api: https://glamanate.com/blog/using-json-api-query-your-search-api-indexes for views: https://www.drupal.org/project/jsonapi/issues/2944204 https://gist.github.com/e0ipso/efcc4e96ca2aed58e32948e4f70c2460   https://www.drupal.org/forum/support/module-development-and-code-questions/2015-11-18/how-do-i-consume-json-from-other   https://github.com/byteparity/rest-api-drupal8 ...

Composer commands

Installing composer packages behind proxy Dont try to install composer packages with sudo. export HTTPS_PROXY_REQUEST_FULLURI=false Other commands: 1. use  composer prohibits package-name to find out the dependency issue with installing that package 2. use composer info package-name to find out what other libraries that package requires If http request failing then force using https. > composer config -g repo.packagist composer https://packagist.org https://github.com/composer/composer/issues/5656#issuecomment-246103054 Install dev modules. Example: local: composer require --dev 'drupal/devel:^4.0' prod:  composer install --no-dev Install new modules: https://stackoverflow.com/questions/15212381/composer-how-can-i-install-another-dependency-without-updating-old-ones Composer cheatsheet https://devhints.io/composer In docker composer If you cant run composer https://stackoverflow.com/questions/28721699/root-password-inside-a-docker-container

PHP Compatability checker

PHPcompatability checker: https://www.drupal.org/node/2924272   https://github.com/PHPCompatibility/PHPCompatibility phpcs - p . -- standard = PHPCompatibility -- extensions = module / php , inc / php , install / php , php / php -- runtime - set testVersion 7.1

Revert a particular git commit

Assume that you commit a change, pushed and there is also a merge commit. Now you want to revert that particular commit. Do the following > git revert <that_particular_merge_hash> -m 1 This automatically creates a commit with the reverted changes. Now push again.

Configuration management in Drupal8

Better source: https://www.slideshare.net/nuvoleweb/advanced-configuration-management-with-config-split-et-al How to (in short): Create one split in local Keep it disabled Enable via config override Enable all the dev modules that you want drush cex => it will  update sync folder and respective split folder(the one which is active) Note: Next export all the configuration (with `drush cex` for drush >= 8.1.10 and `drush csex` for older versions of drush).

Set up Drupal8 development site locally from production clone

1. Dump the production db and import locally prodsite > drush sql-dump > /nonwebrootpath/prod.sql 2. Clone the code and files of production locally Assume you are making production clone site in local folder "devsite" 3. Change the sites/default/setttings.php a) change db name in  databases [ 'default' ][ 'default' ] b) 4. Create database  devsite> drush sql-create --db-url=mysql://root:mysqlpassword@localhost/test860 5. Import database devsite> drush sql-query --file=/nonwebrootpath/prod.sql 6. Clear cache devsite> drush cache-rebuild

Find the version of package before installing in Ubuntu

apt-get -s install <package> Example: apt-get -s install php NOTE: This is only a simulation! apt-get needs root privileges for real execution. Keep also in mind that locking is deactivated, so don't depend on the relevance to the real current situation! Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: php-common php7.0 php7.0-cli php7.0-common php7.0-fpm php7.0-json php7.0-opcache php7.0-readline Suggested packages: php-pear The following NEW packages will be installed: php php-common php7.0 php7.0-cli php7.0-common php7.0-fpm php7.0-json php7.0-opcache php7.0-readline 0 upgraded, 9 newly installed, 0 to remove and 35 not upgraded. Inst php-common (1:35ubuntu6.1 Ubuntu:16.04/xenial-updates [all]) Inst php7.0-common (7.0.30-0ubuntu0.16.04.1 Ubuntu:16.04/xenial-updates, Ubuntu:16.04/xenial-security [amd64]) Inst php7.0-json (7.0.30-0ubuntu0.16.04.1 Ub...

All about views handlers code

The header, footer in views is called "view area" For example, you need to write views handlers to conditionally display header, footer. class views_handler_area_spellcheck extends views_handler_area { } Example module to look for is search_api_spellcheck

Drupal drush make file example

https://www.drupal.org/node/2843391

Drupal8 installation profiles and distributions - notes

The installation profile is optional during the installation. If a installation profile is marked as distribution then it is always run during the installation. example installation profile https://github.com/rakeshjames/example_profile How to create an install profile. http://www.thecarneyeffect.co.uk/creating-installation-profile https://github.com/drupal-cod/cod_kickstart Simple use case:  If the site is installed with install profile 'innovation' then media module is enabled and content type 'project' is created. Steps: a) source site 1. Install Drupal8 (source_d8) 2. Enable media module 3. Create a content type called 'project' 4. Export all the configuration - drush cex If you installed Drupal8 via composer-template then the configuration files are here. yourinstall/config/sync/install b) target site: 1. Install Drupal8 (target_d8) 2. Create a profile using drupal console (if necessary) target_d8 > drupal generate:profile  \ ...

How to override a routing and controller in Drupal8

When using below module this is what happens 1. /user/login => page not found 2. /login1234 => shows login page (user.login route is hijacked by this modules route subscriber) 3. /login1234 => shows text "hello world" (user.login controller is hijacked by this modules route subscriber) example_module.info.yml name: 'example_module' type: module description: 'My Awesome Module' core: 8.x package: 'Custom' example_module/example_module.services.yml services:   example_module.route_subscriber:     class: Drupal\example_module\Routing\RouteSubscriber     tags:       - { name: event_subscriber } example_module/ example_module.module <?php /**  * @file  * Contains example_module.module.  */ use Drupal\Core\Routing\RouteMatchInterface; /**  * Implements hook_help().  */ function example_module_help($route_name, RouteMatchInterface $route_match) {   switch ($route_name) {...

Drupal console hacks

drupal generate:routesubscriber  \ --module="example_module"  \ --name="example_module.route_subscriber"  \ --class="RouteSubscriber"

Install drupal using drupal-composer

Step1: Download Drupal8 and its dependencies using composer >sudo composer create-project drupal-composer/drupal-project:~8.5 drupal85 --stability dev --no-interaction This will install drush and drupal-console Reference: https://www.drupal.org/docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies Step2: Install Drupal using Drush drupal85> sudo vendor/bin/drush site-install --db-url=mysql://username:password@host/dbname For the record: - 8.x-dev is already referring to the version of the project template, the --stability dev is redundant, has been removed in the mean time. - drupal-composer/drupal-project doesn't come in a stable version. The only one available is dev.  - the project template flavor doesn't say anything on what will be required upon install. You need to check composer.json on version constraints  for that. - there are other project templates that do release specific versions. You wouldn't provide the version c...

Multisite Drupal reference

Memcache support for multisites: for each site settings.php add the following line. $conf['memcache_key_prefix'] = 'mysite1';

Solr commands reference

Install Solr8.1 ========== 1. Start the solr cd solr-8.5.1 bin/solr start 2. Enable basic authentication plugin (standalone mode) cd server/solr vim security.json {    "authentication":{       "blockUnknown":true,       "class":"solr.BasicAuthPlugin",       "credentials":{          "solr":"vxxGVpJ0SiWA3LgtLCX8U+b3kGnFjS4CsT27Zz3g+MQ= iRFoY1CY1uFO6PgkugiN30eapYJ5SKFiHhBuy8O4rg0="       },       "realm":"My Solr users",       "forwardCredentials":false,       "":{          "v":0       }    },    "authorization":{       "class":"solr.RuleBasedAuthorizationPlugin",       "permissions":[          {             "name":"security-edit",             "role":"admin"       ...

Symfony3.4 and Drupal console commands reference

php bin/console list php bin/console generate:controller Symfony console: What we are going to do? 1. Install symfony at http://127.0.0.1:8001 2. Create a controller at  http://127.0.0.1:8001/products 3.  Create a controller at  http://127.0.0.1:8001/product Installing symfony: 1. apache-doc-root> composer create-project symfony/framework-standard-edition autotrader2 2. autotrader2> php bin/console server:run It should show like  [OK] Server listening on http://127.0.0.1:8001  3. Run in browser http://127.0.0.1:8001 It should say Welcome to Symfony 3.4.4 Create a controller at  http://127.0.0.1:8001/products Generate bundle: 1. autotrader2> php bin/console generate:bundle Note: a) Give bundle name as ProductBundle b) If following error occurs Checking that the bundle is autoloaded FAILED then add  "ProductBundle\\": "src/ProductBundle" in composer.json . So it should look like this "psr-4": { ...

Drupal7 vs Drupal8 hooks - reference

An excellent reference https://x-team.com/blog/drupal-8-hooks/