Drupal 8 - Drupal 8 - News - Help - Tutorial - And more... http://drupal8.ovh/en/rss.xml en Use multiple databases on drupal 8 http://drupal8.ovh/en/tutoriels/285/use-multiple-databases-on-drupal-8 <span class="field field--name-title field--type-string field--label-hidden">Use multiple databases on drupal 8</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to use multiple databases to move some tables from main database.</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Wed, 01/18/2017 - 17:23</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h2>Move some tables into another database.</h2> <p>Example:</p> <p><code>$databases['default']['default'] = array(<br />   'database' =&gt; 'drupal8_default',<br />   'username' =&gt; 'root',<br />   'password' =&gt; 'THEPASSWORD',<br />   'host' =&gt; 'localhost',<br />   'port' =&gt; '3306',<br />   'namespace' =&gt; 'Drupal\\Core\\Database\\Driver\\mysql',<br />   'driver' =&gt; 'mysql',</code></p> <p><code>  //Add prefix to separate databases<br />   'prefix' =&gt; array(<br />     //Use a shared database for the users (not recomended, Just for example)<br />     'users' =&gt; 'drupal8_shared.',</code></p> <p><code>    //Move cache into another database<br />     'cache_bootstrap' =&gt; 'drupal8_cache.',<br />     'cache_config' =&gt; 'drupal8_cache.',<br />     'cache_container' =&gt; 'drupal8_cache.',<br />     'cache_data' =&gt; 'drupal8_cache.',<br />     'cache_default' =&gt; 'drupal8_cache.',<br />     'cache_discovery' =&gt; 'drupal8_cache.',<br />     'cache_dynamic_page_cache' =&gt; 'drupal8_cache.',<br />     'cache_entity' =&gt; 'drupal8_cache.',<br />     'cache_menu' =&gt; 'drupal8_cache.',<br />     'cache_render' =&gt; 'drupal8_cache.',<br />     'cache_toolbar' =&gt; 'drupal8_cache.',<br />   ),<br /> );</code></p> <p><code>//Configure shared database<br /> $databases['shared']['default'] = array(<br />   'database' =&gt; 'drupal8_shared',<br />   'username' =&gt; 'root',<br />   'password' =&gt; 'THEPASSWORD',<br />   'host' =&gt; 'localhost',<br />   'port' =&gt; '3306',<br />   'namespace' =&gt; 'Drupal\\Core\\Database\\Driver\\mysql',<br />   'driver' =&gt; 'mysql',<br /> );</code></p> <p><code>//Configure cache database<br /> $databases['cache']['default'] = array(<br />   'database' =&gt; 'drupal8_cache',<br />   'username' =&gt; 'root',<br />   'password' =&gt; 'THEPASSWORD',<br />   'host' =&gt; 'localhost',<br />   'port' =&gt; '3306',<br />   'namespace' =&gt; 'Drupal\\Core\\Database\\Driver\\mysql',<br />   'driver' =&gt; 'mysql',<br /> );</code></p> <p> </p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/database" hreflang="en">Database</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/175/use-multiple-databases-drupal-8" hreflang="en">Use multiple / external databases in Drupal 8</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=285&amp;2=comment&amp;3=comment" token="93a5ab0d"></drupal-render-placeholder> </section> Wed, 18 Jan 2017 16:23:02 +0000 editor 285 at http://drupal8.ovh Create an advances Search system for Drupal 8 with Search API. http://drupal8.ovh/en/tutoriels/284/create-a-advances-search-system-for-drupal-8-search-api <span class="field field--name-title field--type-string field--label-hidden">Create an advances Search system for Drupal 8 with Search API.</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to use advances search server like Solr, Elasticsearch, Database ... With a Drupal 8 site ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Wed, 01/18/2017 - 12:03</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h2>Search API and Database Search server.</h2> <p>1. Uninstall drupal basic Search<br /> 2. Install search_api and search_api_db<br />   NOTE : You can also use another database configures on settings.php<br /> 3. Add a Search Server (/admin/config/search/search-api/add-server).<br />   - Use "Database" as cackend server.<br /> 3. Add a Search Index (/admin/config/search/search-api/add-index).<br />   - Select Enteties (Data source) to index with this index and a search server.<br />   - Save and Add fields to Index. (Example : Title, Body file for "Contents").<br />   - Optionaly you can configure "Processors" as Filters, Data traitements ...<br /> 4. Enable the newly created "Index" then run indexing or queue indexing.<br /> 5. Create a view using your Index, and add field "Search: Fulltext search" as Exposed criteris filter.</p> <p>Once indexing is done, visit the view's page to use the search system.</p> <p> </p> <p><strong>Tips </strong>: For a quick start, just install the "Database Search Defaults" (), and configure your "Search Server", "Index" and "Search Pages" on.<br />  - Search API :        /admin/config/search/search-api<br />  - Search Views :    /admin/structure/views (Defaut : /admin/structure/views/view/search_content )</p> <p><em>NOTE : To create a server like Solr, Elasticsearch you need to install search server and the drupal module for those servers.</em></p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/search" hreflang="en">Search</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=284&amp;2=comment&amp;3=comment" token="329c2fe3"></drupal-render-placeholder> </section> Wed, 18 Jan 2017 11:03:57 +0000 editor 284 at http://drupal8.ovh Create a field in a node entity programmatically on Drupal 8. http://drupal8.ovh/en/tutoriels/283/create-a-field-a-node-entity-programmatically-on-drupal-8 <span class="field field--name-title field--type-string field--label-hidden">Create a field in a node entity programmatically on Drupal 8.</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to create a custom field in a node entity programmatically, using field API on  drupal 8.</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Fri, 01/13/2017 - 11:37</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Example.<br /> Step 1 : Create field storage.<br /><code>\Drupal\field\Entity\FieldStorageConfig::create(array(<br />   'field_name' =&gt; 'field_text',<br />   'entity_type' =&gt; 'node',<br />   'type' =&gt; 'text',<br />   'cardinality' =&gt; -1,<br /> ))-&gt;save();</code></p> <p>Step 2 : Attach an instance of the field to the page content type.<br /><code>\Drupal\field\Entity\FieldConfig::create([<br />   'field_name' =&gt; 'field_text',<br />   'entity_type' =&gt; 'node',<br />   'bundle' =&gt; 'page',<br />   'label' =&gt; 'A Text field',<br /> ])-&gt;save();</code></p> <p>Step 3 : Set From Display<br /><code>entity_get_form_display('node', 'page', 'default')<br />   -&gt;setComponent('field_text', array(<br />     'type' =&gt; 'text_textfield',<br />   ))<br />   -&gt;save();</code></p> <p>Step 4 : Set Display<br /><code>entity_get_display('node', 'page', 'default')<br />   -&gt;setComponent('field_text', array(<br />     'type' =&gt; 'text_default',<br />   ))<br />   -&gt;save();</code></p> <p>Tips</p> <p>Load the field:<br /><code>$field_config = \Drupal\field\Entity\FieldStorageConfig::loadByName('node', 'field_text');</code></p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/field" hreflang="en">Field</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/263/custom-content-entity-field-types-of-drupal-8" hreflang="en">Custom Content Entity Field types of drupal 8</a></div> <div class="field__item"><a href="/en/tutoriels/58/get-field-value-of-a-node-entity" hreflang="en">Get field value of a Node / Entity</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=283&amp;2=comment&amp;3=comment" token="e3d2bdeb"></drupal-render-placeholder> </section> Fri, 13 Jan 2017 10:37:42 +0000 editor 283 at http://drupal8.ovh CSS Styling tips for Print http://drupal8.ovh/en/tutoriels/282/css-styling-tips-for-print <span class="field field--name-title field--type-string field--label-hidden">CSS Styling tips for Print</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to create a css for print on drupal 8 ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Thu, 01/12/2017 - 15:56</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h2>Add CSS for Print</h2> <h3>Method 1 : Add a specific styling sheet for Print.</h3> <p>On your theme (THEME.info.yml for D8 and THEME.info for D7), Add css file as [print].<br /> Example<br /><code>stylesheets[print][] = css/print.css</code></p> <p> </p> <h3>Method 1. In Same style sheet.</h3> <p>Wrap codes for print using @media query.<br /> Example:<br /><code>@media print<br /> {<br />   /*Codes For Print*/<br /> }</code></p> <h2>Tips:</h2> <h3>Remove the URL and SRC from print css (Hide address)</h3> <p><code>  a[href]:after { content: none !important; }<br />   img[src]:after { content: none !important; }</code></p> <h3>Add Print Button (Or image)</h3> <p>Example:<br /><code>&lt;img src="print.png" alt="Print" onclick="window.print()"&gt;<br /> &lt;button onclick="window.print()"&gt;Print&lt;/button&gt;</code></p> <p> </p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/264/basic-css-styling-tips" hreflang="en">Basic CSS Styling tips</a></div> <div class="field__item"><a href="/en/tutoriels/22/add-css-to-a-module" hreflang="en">Add CSS stylesheets to a module</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=282&amp;2=comment&amp;3=comment" token="42eb3905"></drupal-render-placeholder> </section> Thu, 12 Jan 2017 14:56:34 +0000 editor 282 at http://drupal8.ovh Make Some operations Programmatically - Hook Update Deploy Tools http://drupal8.ovh/en/tutoriels/281/make-some-operations-programmatically-hook-update-deploy-tools <span class="field field--name-title field--type-string field--label-hidden">Make Some operations Programmatically - Hook Update Deploy Tools</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to make deploy operations programmatically ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Wed, 01/11/2017 - 11:33</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><strong>Hook Update Deploy Tools</strong> is a great contrib module help to make most of site deploy operations programmatically.<br /> Link : https://www.drupal.org/project/hook_update_deploy_tools</p> <p>CAUTION : Current drupal 8 version is unstable (8.x-1.0-unstable1, 2016-Feb-07 Version),  but 8.x-1.x-dev version is usable.</p> <h3>Example: Delete a field instance.<br /> Using contrib module hook_update_deploy_tools</h3> <p>//Drupal 8:<br /> $message = \HookUpdateDeployTools\Fields::deleteInstance('taxonomy_term', 'field_name', 'tags');</p> <p>//Drupal 7:  <br /> $message = HookUpdateDeployTools\Fields::deleteInstance('taxonomy_term', 'field_name', 'tags');</p> <p> </p> <p>Without Hook Update Deploy Tools<br /> //Drupal 8:</p> <p>//Drupal 7:<br /> $instance = field_info_instance('node', 'field_name', 'page');//For node<br /> $instance = field_info_instance('taxonomy_term', 'field_name', 'tags');//For taxonomy term<br /> if ($instance) {<br />   field_delete_instance($instance);<br /> }</p> <p>//D8 (Not tested)<br /> $field_info = \Drupal\field\Entity\FieldConfig::loadByName('node', 'page', 'field_name');<br /> $field_info-&gt;delete();</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/drupal-7" hreflang="en">Drupal 7</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/223/change-drupal-8-text-field-maximum-length" hreflang="en">Change Drupal 8 text field maximum length</a></div> <div class="field__item"><a href="/en/tutoriels/263/custom-content-entity-field-types-of-drupal-8" hreflang="en">Custom Content Entity Field types of drupal 8</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=281&amp;2=comment&amp;3=comment" token="7ad0b276"></drupal-render-placeholder> </section> Wed, 11 Jan 2017 10:33:42 +0000 editor 281 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/281/make-some-operations-programmatically-hook-update-deploy-tools#comments Get Entity data and metadata http://drupal8.ovh/en/tutoriels/280/get-entity-deta-and-metadata <span class="field field--name-title field--type-string field--label-hidden">Get Entity data and metadata</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to get Entity type data and metadata</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Tue, 01/10/2017 - 13:11</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Get entity types list :</p> <p><span>$itmes_list= \Drupal::</span><em>entityTypeManager</em><span>()-&gt;getDefinitions();</span></p> <p><span>Get Entity type (Content / Config)</span></p> <p><span>$itmes_list['node']-&gt;getGroup();<br /> $itmes_list['node_type']-&gt;getGroup();</span></p> <p><span>Get Label / Name</span></p> <p><span>$itmes_list['node']-&gt;getLabel();</span></p> <p> </p> <p>Load entity (dynamic type) from database</p> <p>\Drupal::entityTypeManager()-&gt;getStorage($entity_type)-&gt;load($id);<br /> See : https://api.drupal.org/api/drupal/core%21includes%21entity.inc/function/entity_load/8.3.x</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/entity" hreflang="en">Entity</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/149/find-entity-using-drupal-entityquery" hreflang="en">Find Entity using Drupal EntityQuery</a></div> <div class="field__item"><a href="/en/tutoriels/149/find-entity-using-drupal-entityquery" hreflang="en">Find Entity using Drupal EntityQuery</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=280&amp;2=comment&amp;3=comment" token="dbe93698"></drupal-render-placeholder> </section> Tue, 10 Jan 2017 12:11:53 +0000 editor 280 at http://drupal8.ovh Manage custom package using composer. http://drupal8.ovh/en/tutoriels/278/manage-custom-package-using-composer <span class="field field--name-title field--type-string field--label-hidden">Manage custom package using composer.</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to manage a custom packages using composer.</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Tue, 01/03/2017 - 14:21</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Composer can hadle CVS (git, svn ...) and ZIP packages.<br /> To install/Update your custom modules, add a custom repository to the composer.json file, following this example.</p> <p>1. Add package repositories<br /> Here, youtubeapi and sadb</p> <p>2. Require packages to install<br /> Here, iwsp/youtubeapi and iwsp/sadb</p> <p>3. Run:  <code><strong>composer update</strong></code></p> <p><code>    "repositories": {<br />         "youtubeapi": {<br />             "type": "package",<br />             "package": {<br />                 "name": "iwsp/youtubeapi",<br />                 "version": "1.0.2",<br />                 "type": "drupal-module",<br />                 "dist": {<br />                     "url": "https://drupal8.ovh/sites/drupal/files/2017-01/youtubeapi.zip",<br />                     "type": "zip"<br />                 }<br />             }<br />         },<br />         "sadb": {<br />             "type": "package",<br />             "package": {<br />                 "name": "iwsp/sadb",<br />                 "type": "drupal-module",<br />                 "version": "1.0.0",<br />                 "source": {<br />                   "url": "https://git.drupal.org/sandbox/NuWans/2795593",<br />                   "type": "git",<br />                   "reference": "8.x-1.x"<br />                 }<br />             }<br />         }<br />     },<br />     "require": {<br />         "composer/installers": "^1.0.21",<br />         "wikimedia/composer-merge-plugin": "~1.3",<br />         "drupal/core": "^8.2",<br /><strong>        "iwsp/youtubeapi": "^1.0",<br />         "iwsp/sadb": "*"</strong><br />     },</code><br />     <br />     <br /> Note : If you are using http:// (not https://) add following config. But its recomended to use SSL.<br /><code>    "config": {<br />         "secure-http": false<br />     },</code></p> </div> <div class="field field--name-field-file field--type-file field--label-inline"> <div class="field__label">File</div> <div class="field__item"> <span class="file file--mime-application-zip file--package-x-generic"> <a href="http://drupal8.ovh/sites/drupal/files/2017-01/youtubeapi.zip" type="application/zip; length=31458">youtubeapi.zip</a></span> </div> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/composer" hreflang="en">Composer</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/277/create-a-drupal-8-project-using-composer" hreflang="en">Create a Drupal 8 Project using composer.</a></div> <div class="field__item"><a href="/en/tutoriels/202/install-and-update-composer" hreflang="en">Install and Update Composer</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=278&amp;2=comment&amp;3=comment" token="89747994"></drupal-render-placeholder> </section> Tue, 03 Jan 2017 13:21:03 +0000 editor 278 at http://drupal8.ovh Create a Drupal 8 Project using composer. http://drupal8.ovh/en/tutoriels/277/create-a-drupal-8-project-using-composer <span class="field field--name-title field--type-string field--label-hidden">Create a Drupal 8 Project using composer.</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to Create a Drupal 8 Project using composer.</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Tue, 01/03/2017 - 14:20</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Get drupal8 using default Packagist.org (The composer packages repository) drupal repository.<br /> composer create-project drupal/drupal drupal8</p> <p>Few other repositorys.<br /> composer create-project drupal/drupal drupal8 --stability dev<br /> composer create-project drupalcommerce/project-base drupal8 --stability dev</p> <p>If you gave a private repository, You can use a <strong>package.json</strong> like:</p> <p><code>{<br />     "package": {<br />         "name": "yourname/your-drupal-project",<br />         "version": "1.0.0",<br />         "dist": {<br />             "url": "https://your.domain/url-to/your-drupal-project.zip",<br />             "type": "zip"<br />         }<br />     }<br /> }</code></p> <p>Then:</p> <p><code>composer create-project yourname/your-drupal-project drupal8 --stability dev --repository=packages.json</code></p> <p> </p> <p> </p> <h3>Tips:</h3> <p>Clear composer cache</p> <p><code>composer clear-cache</code></p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/composer" hreflang="en">Composer</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/202/install-and-update-composer" hreflang="en">Install and Update Composer</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=277&amp;2=comment&amp;3=comment" token="51a1df2b"></drupal-render-placeholder> </section> Tue, 03 Jan 2017 13:20:12 +0000 editor 277 at http://drupal8.ovh Drupal 8 Url Tips. Get Name, Path, Args ... http://drupal8.ovh/en/tutoriels/275/drupal-8-url-tips-get-name-path-args <span class="field field--name-title field--type-string field--label-hidden">Drupal 8 Url Tips. Get Name, Path, Args ...</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to get Url Object From Path ?<br /> How to get route data from Url Object?</p> <p> </p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Tue, 12/20/2016 - 10:26</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Drupal 8 Url Object<br /><code>use Drupal\Core\Url;</code></p> <h2>Create a Url</h2> <h3>Create Url from route name</h3> <p><code>$url = Url::fromRoute('&lt;current&gt;');<br /> $url = Url::fromRoute('entity.node.canonical', ['node' =&gt; 1], []);</code></p> <p>//Get Path/Route from Url Object<br /><code>$url = Url::fromRoute('entity.node.canonical', ['node' =&gt; 1], []);<br /> if ($url-&gt;isRouted()) {<br />   $out = $url-&gt;toString(); // Get : /en/node/1<br />   $out = $url-&gt;getInternalPath(); // Get : node/1<br />   $out = $url-&gt;getRouteName(); // Get : entity.node.canonical<br />   $out = $url-&gt;getRouteParameters(); // Get : Array ([node] =&gt; 1)<br />   $out = $url-&gt;getOptions(); // Get : Array ()<br /> }</code></p> <h3>Create a route from external Uri</h3> <p>Get Data from External Url Object<br /><code>$url = Url::fromUri("http://www.drupal8.ovh/en/tutoriels/275/drupal-8-url-tips-get-name-path-args?test=yes");<br /> if ($url-&gt;isExternal()) {<br />   $out = $url-&gt;toString();//Get : http://www.drupal8.ovh/en/tutoriels/275/drupal-8-url-tips-get-name-path-args?test=yes<br />   $out = $url-&gt;getOptions(); // Get : Array([external] =&gt; 1)<br />   $out = $url-&gt;getUri(); //Get : http://www.drupal8.ovh/en/tutoriels/275/drupal-8-url-tips-get-name-path-args?test=yes<br /> }</code></p> <p>Note : If you are not sure, its better to use try ant chtch to avoid exceptions.<br /><code>try {<br />   $url-&gt;getUri();<br /> }<br /> catch (\Exception $e) {<br />   drupal_set_message("Has internam path : " . $url-&gt;toString());<br /> }</code></p> <h3>Create a route from internal Uri</h3> <p>Example :<br /><code>$url = Url::fromUserInput("/node/1");</code></p> <p>//TODO : <span>$url </span><span>= Url::</span><em>fromRouteMatch</em><span>(</span><span>$route_match</span><span>);</span></p> <h2> Get Url from path validator service.</h2> <p>Drupal has path validator service : PathValidatorInterface::getUrlIfValid()<br /><code>\Drupal::service('path.validator')-&gt;getUrlIfValid('node/1');</code></p> <p> </p> <p> </p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/79/get-args-from-url-drupal-8" hreflang="en">Get args from URL in Drupal 8</a></div> <div class="field__item"><a href="/en/tutoriels/57/get-node-from-url" hreflang="en">Get node from url</a></div> <div class="field__item"><a href="/en/tutoriels/27/get-current-page-uri-on-drupal-8" hreflang="en">Get the current page URI on Drupal 8</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=275&amp;2=comment&amp;3=comment" token="c8a3d0b6"></drupal-render-placeholder> </section> Tue, 20 Dec 2016 09:26:18 +0000 editor 275 at http://drupal8.ovh Notify When SSH connection success http://drupal8.ovh/en/tutoriels/274/notify-when-ssh-connection-success <span class="field field--name-title field--type-string field--label-hidden">Notify When SSH connection success</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to notify by email, url, SMS ... When SSH connection success ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Fri, 12/16/2016 - 13:45</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h2>Method 1. Call Url</h2> <p> You can use this method to call a Custom php script, Custom module, Databaselog .... for example.</p> <p>1. Create a script (here, notify_login_url.sh)</p> <p><code>#Example 1.<br /> #!/bin/sh<br /> # Configure your Url:<br /> URL="http://www.yoursite.com/yourscript.php?var=1";<br /> wget $URL &gt; /dev/null 2&gt;&amp;1</code></p> <p><code>#Or Example 2.</code><br /><code>#!/bin/sh</code><br /><code># Configure your Url:<br /> HOST="`hostname`";<br /> NOW=$(date +"%Y-%m-%d:%H:%M:%S");<br /> URL="http://domain.net/mail/notify.php?c=notifyme&amp;t=Connection/Dis++On:+VPS++$PAM_USER++$PAM_RHOST+on+$HOST++$NOW";<br /> curl $URL &amp;&gt;/dev/null;</code></p> <p> </p> <p>2. Make the script executable<br /><code>chmod +x notify_login_url.sh</code></p> <p>3. Add the script to /etc/pam.d/sshd<br /> session optional pam_exec.so seteuid /path/to/notify_login_url.sh</p> <p> NOTE 1 : This will also call on disconnection</p> <p>NOTE 2 :<br /> Set "optional" If you want to still log in if the execution fails.<br /> CAUTION : Set "required" Only After you made sure that it works and if your are sure about what you are doing . login won't be possible unless the execution of your hook script is successful.</p> <h2>Method 2. Send e-Mail using mailx</h2> <p>1. Create a script (here, notify_login_mailx.sh) and make it make it executable (chmod +x notify_login_mailx.sh).</p> <p><code>#!/bin/sh<br /> # Configure your email address:<br /> sender="sender-address@example.com"<br /> recepient="notify-address@example.com"</code></p> <p><code>if [ "$PAM_TYPE" != "close_session" ]; then<br />     host="`hostname`"<br />     subject="SSH Login: $PAM_USER from $PAM_RHOST on $host"<br />     # Message to send, e.g. the current environment variables.<br />     message="`env`"<br />     echo "$message" | mailx -s "$subject" "$recepient"<br />     #OR#echo "$message" | mailx -r "$sender" -s "$subject" "$recepient"<br /> fi</code></p> <p>2. Add the script to /etc/pam.d/sshd<br /> session optional pam_exec.so seteuid /path/to/notify_login_mailx.sh</p> <p> </p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/server" hreflang="en">Server</a></li> <li><a href="/en/tags/linux" hreflang="en">Linux</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=274&amp;2=comment&amp;3=comment" token="699a5458"></drupal-render-placeholder> </section> Fri, 16 Dec 2016 12:45:38 +0000 editor 274 at http://drupal8.ovh