Drupal 8 - Drupal 8 - News - Help - Tutorial - And more... http://drupal8.ovh/en/rss.xml en SSH Login Without Password http://drupal8.ovh/en/tutoriels/298/ssh-login-without-password <span class="field field--name-title field--type-string field--label-hidden">SSH Login Without Password</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 Perform SSH Login Without Password Using ssh-keygen &amp; ssh-copy-id ?</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, 03/22/2017 - 23:26</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Method 1:</p> <p><code>#Generate SSH Private/Public key pair.<br /> ssh-keygen<br /> #Add public key to the server<br /> ssh-copy-id -i ~/.ssh/id_rsa.pub name@domain.com<br /> #If you have a message like : sign_and_send_pubkey: signing failed: agent refused operation, Add the key using:<br /> ssh-add</code></p> <p>Method 2: (Not tested)</p> <p><code>ssh-keygen -t rsa<br /> ssh name@domain.com mkdir -p .ssh<br /> cat ~/.ssh/id_rsa.pub | ssh name@domain.com 'cat &gt;&gt; .ssh/authorized_keys'<br /> ssh name@domain.com "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"</code></p> <p> </p> <h3>Remove a key (On server)</h3> <ol><li>Login to the server</li> <li>Edit file <code>.ssh/authorized_keys</code>, Delete the unwanted key</li> </ol></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/server" hreflang="en">Server</a></li> <li><a href="/en/tags/linux" hreflang="en">Linux</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/23/ssh-renew-remove-remote-host-identification" hreflang="en">SSH Renew / Remove remote host identification.</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=298&amp;2=comment&amp;3=comment" token="9561f4d4"></drupal-render-placeholder> </section> Wed, 22 Mar 2017 22:26:50 +0000 editor 298 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/298/ssh-login-without-password#comments Static cache Control by .htacces http://drupal8.ovh/en/tutoriels/297/static-cache-control-by-htacces <span class="field field--name-title field--type-string field--label-hidden">Static cache Control by .htacces</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 enable static cache Control using .htacces ?</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">Mon, 03/20/2017 - 20:31</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h3>Static cache Control by .htacces</h3> <p>If not already done, you must enable apache headers (mod_headers.c) module</p> <p>Check module is enabled or not:<br /><code>ls /etc/apache2/mods-enabled/</code></p> <p>Eneble module:<br /><code>sudo a2enmod headers<br /> sudo service apache2 restart</code></p> <p> Add Cache controle to .htaccess file:exit</p> <p><code>#Static cache<br /> &lt;IfModule mod_headers.c&gt;<br />     #2592000 = 1Year, 86400=24h<br />     #CSS and JS files<br />     &lt;filesMatch "\.(js|css)$"&gt;<br />       Header set Cache-Control "max-age=2592000, public"<br />     &lt;/filesMatch&gt;<br />     #Images<br />     &lt;filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$"&gt;<br />       Header set Cache-Control "max-age=2592000, public, must-revalidate"<br />     &lt;/filesMatch&gt;<br />     #Fonts<br />     &lt;filesMatch "\.(ttf|woff)$"&gt;<br />       Header set Cache-Control "max-age=2592000, public, must-revalidate"<br />     &lt;/filesMatch&gt;<br />     # Disable caching for scripts and other dynamic files<br />     &lt;FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"&gt;<br />       Header unset Cache-Control<br />     &lt;/FilesMatch&gt;<br /> &lt;/IfModule&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/linux" hreflang="en">Linux</a></li> <li><a href="/en/tags/server" hreflang="en">Server</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=297&amp;2=comment&amp;3=comment" token="4db4526b"></drupal-render-placeholder> </section> Mon, 20 Mar 2017 19:31:49 +0000 editor 297 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/297/static-cache-control-by-htacces#comments Avoid Spam form submissions - (Easy way of form Anti-Spam) http://drupal8.ovh/en/tutoriels/296/avoid-spam-form-submissions-easy-way-of-form-anti-spam <span class="field field--name-title field--type-string field--label-hidden">Avoid Spam form submissions - (Easy way of form Anti-Spam)</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 avoid spam contact form or other form submissions by robots (spam-bots) ?</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, 03/16/2017 - 10:14</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><strong>Method 1. (Classical way)</strong></p> <p>Use a captcha system like Math captcha, Image captcha, reCaptcha of google....</p> <h2>Method 2. Use Honeypot</h2> <p>Honeypot use a very simple method to limit unwanted form submission by robots (any way, some robots can pass through this method). This method can block up to 98% of spam form submissions.</p> <h3>Concept of Honeypot.</h3> <p>By adding an invisible field to your forms that only spambots can see, you can trick them into revealing that they are spam bots and not actual end-users.</p> <p>Here we have a simple checkbox that:</p> <ul><li>Is hidden with CSS.</li> <li>Has an obscure but obviously fake name.</li> <li>Has a default value equivalent 0.</li> <li>Can't be filled by auto-complete</li> <li>Can't be navigated to via the Tab key. (See tabindex)</li> </ul><h3>Install / Implement Honeypot on drupal.</h3> <p>Just install and configure drupal Honeypot contrib module.</p> <h3><br /> Install / Implement Honeypot on custom PHP Website.</h3> <h4>HTML Code</h4> <p><code>&lt;input type="checkbox" name="contact_me_by_fax_only" value="1" style="display:none !important" tabindex="-1" autocomplete="off"&gt;</code></p> <p> </p> <h4>Server-Side</h4> <p>On the server side we want to check to see if the value exists and has a value other than 0, and if so handle it appropriately. This includes logging the attempt and all the submitted fields.</p> <p>In PHP it might look something like this:</p> <p><code>$honeypot = FALSE;<br /> if (!empty($_REQUEST['contact_me_by_fax_only']) &amp;&amp; (bool) $_REQUEST['contact_me_by_fax_only'] == TRUE) {<br />     $honeypot = TRUE;<br />     log_spambot($_REQUEST);<br />     // treat as spambot<br /> } else {<br />     // process as normal<br /> }</code></p> <h2><br /> An Example of Honeypot php class for easy implementation.</h2> <h3>PHP Class</h3> <p><code>&lt;?php<br /><br /> class Honeypot {<br /><br />   const FIELD_NAME = "contact_me_by_fax_only";<br /><br />   /**<br />    * Get Honeypot form input field.<br />    * @return string<br />    */<br />   public static function getHoneypot() {<br />     $field_name = self::FIELD_NAME;<br />     $form_input = '&lt;input type="checkbox" name="' . $field_name . '" value="1" style="display:none !important" tabindex="-1" autocomplete="off"&gt;';<br />     return $form_input;<br />   }<br /><br />   /**<br />    * Check the form submission.<br />    * @return bool<br />    */<br />   public static function checkHoneypot() {<br />     $honeypot = FALSE;<br />     $field_name = self::FIELD_NAME;<br />     if (!empty($_REQUEST[$field_name]) &amp;&amp; (bool) $_REQUEST[$field_name] == TRUE) {<br />       $honeypot = TRUE;<br />     }<br />     return $honeypot;<br />   }<br /> }</code></p> <p> </p> <h3>Usage:</h3> <h4>At the form creation:</h4> <p><code>&lt;form&gt;<br />     ...<br />   &lt;?php print Honeypot::getHoneypot(); ?&gt;<br />     ...<br /> &lt;/form&gt;</code></p> <h4><br /> At the form submission:</h4> <p><code>if (Honeypot::checkHoneypot()) {<br />   // Probably a spam.<br /> }<br /> else {<br />   // Probably not a spam.<br /> }</code></p> <p> </p> <p>Source : http://stackoverflow.com/questions/36227376/better-honeypot-implementation-form-anti-spam</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/php" hreflang="en">PHP</a></li> <li><a href="/en/tags/form" hreflang="en">Form</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=296&amp;2=comment&amp;3=comment" token="ec8dd685"></drupal-render-placeholder> </section> Thu, 16 Mar 2017 09:14:04 +0000 editor 296 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/296/avoid-spam-form-submissions-easy-way-of-form-anti-spam#comments Display a web page as print. Media Print Emulate For development and test http://drupal8.ovh/en/tutoriels/294/display-a-web-page-as-print-media-print-emulate-for-development-and-test <span class="field field--name-title field--type-string field--label-hidden">Display a web page as print. Media Print Emulate For development and test</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 show a web page as print stylesheets to avoid print preview every time (for development and test) on Firefow and /or Chrome ?</p> <p>How to inspect HTML page and elements as <strong>media print</strong> ?</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, 03/08/2017 - 10:10</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h2>Media Print Emulate on Chrome</h2> <p><strong>(Tested on Chrome Version 56)</strong></p> <ol><li>Open Chrome DevTools (<code>F12</code>)</li> <li>Click ⋮ (vertical ellipsis)</li> <li>Choose <strong>More tools</strong> -&gt; <strong>Rendering</strong></li> <li>Tick <strong>Emulate CSS Media</strong></li> <li>Select <strong>print</strong></li> </ol><p> </p> <h2>Media Print Emulate on FireFox</h2> <p><strong>(Tested on Version 51)</strong></p> <ol><li>Open a Developer Toolbar command line (<code>Shift + F2</code>)</li> <li>Type:     <code>media emulate print</code></li> </ol></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/css" hreflang="en">CSS</a></li> <li><a href="/en/tags/theming" hreflang="en">Theming</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=294&amp;2=comment&amp;3=comment" token="758fd918"></drupal-render-placeholder> </section> Wed, 08 Mar 2017 09:10:51 +0000 editor 294 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/294/display-a-web-page-as-print-media-print-emulate-for-development-and-test#comments Create a View Plugin Without using Database field http://drupal8.ovh/en/tutoriels/293/create-a-view-plugin-without-using-database-field <span class="field field--name-title field--type-string field--label-hidden">Create a View Plugin Without using Database field</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 View Plugin Without using Database field , to use with an existence entity (Node, Taxonomy, user ...) ?</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, 03/03/2017 - 13:53</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h3>Step 1. Create a <a href="/en/tutoriels/3/create-a-simple-module-for-drupal-8">custom module</a> and add the HOOK hook_views_data_alter(&amp;$data). Here module : <strong>mymodule</strong></h3> <h3>Step 2. Alter views data, Example</h3> <p><code>function mymodule_views_data_alter(&amp;$data) {<br />   //Add to <strong>Node</strong> views<br />   $data['node']['<strong>random_value</strong>'] = array(<br />     'field' =&gt; array(<br />       'id' =&gt; '<strong>random_value</strong>',<br />       'title' =&gt; t('Random value'),<br />       'help' =&gt; t('Example of random value plugin.'),<br />     ),<br />   );</code></p> <p><code>  //Add to <strong>Taxonomy</strong> views<br />   $data['taxonomy_term_data']['<strong>random_value</strong>'] = array(<br />     'field' =&gt; array(<br />       'id' =&gt; '<strong>random_value</strong>',<br />       'title' =&gt; t('Random value'),<br />       'help' =&gt; t('Example of random value plugin.'),<br />     ),<br />   );</code></p> <p><code>  //Add to <strong>Users</strong> views<br />   $data['users']['<strong>random_value</strong>'] = array(<br />     'field' =&gt; array(<br />       'id' =&gt; '<strong>random_value</strong>',<br />       'title' =&gt; t('Random value'),<br />       'help' =&gt; t('Example of random value plugin.'),<br />     ),<br />   );</code><br /> }</p> <p> </p> <h3>Step 3. Create view plugin on your custom mudule. (Here the minimum necessary to create a plugin)</h3> <p> </p> <p><strong>Examlple : mymodule/src/Plugin/views/field/RandomValue.php</strong></p> <p>Plugin with minimim settings.</p> <p><code>&lt;?php</code></p> <p><code>namespace Drupal\mymodule\Plugin\views\field;</code></p> <p><code>use Drupal\views\Plugin\views\field\FieldPluginBase;<br /> use Drupal\views\ResultRow;<br /> use Drupal\Core\Form\FormStateInterface;</code></p> <p><code>/**<br />  * Default implementation of the base field plugin,<br />  *<br />  * @ingroup views_field_handlers<br />  *<br />  * @ViewsField("random_value")<br />  */<br /> class RandomValue extends FieldPluginBase {</code></p> <p><em><strong><code>  /**<br />    * This is the most important part of this plugin.<br />    * Empty query methode, Allow to create field without database table field.<br />    */<br />   public function query() {<br />     //Must leave blank<br />   }</code></strong></em></p> <p><code>  /**<br />    * {@inheritdoc}<br />    */<br />   public function render(ResultRow $values) {<br />     //Retun your custom vaule, Here, a random value.<br />     return "Random value is : " . rand(0, 1000);<br />   }</code></p> <p><code>}</code></p> <p> </p> <p> </p> <h2> Complete plugin with few other settings</h2> <p><code>&lt;?php</code></p> <p><code>namespace Drupal\mymodule\Plugin\views\field;</code></p> <p><code>use Drupal\views\Plugin\views\field\FieldPluginBase;<br /> use Drupal\views\ResultRow;<br /> use Drupal\Core\Form\FormStateInterface;</code></p> <p><code>/**<br />  * Default implementation of the base field plugin,<br />  *<br />  * @ingroup views_field_handlers<br />  *<br />  * @ViewsField("random_value")<br />  */<br /> class RandomValue extends FieldPluginBase {</code></p> <p><code>  /**<br />    * This is the most important part of this plugin.<br />    * Empty query methode, Allow to create field without database table field.<br />    */<br />   public function query() {<br />     //Must leave blank<br />   }</code></p> <p><code>  /**<br />    * {@inheritdoc}<br />    */<br />   protected function defineOptions() {<br />     $options = parent::defineOptions();<br />     $options['add_text'] = array('default' =&gt; 0);<br />     return $options;<br />   }</code></p> <p><code>  /**<br />    * {@inheritdoc}<br />    */<br />   public function buildOptionsForm(&amp;$form, FormStateInterface $form_state) {</code></p> <p><code>    $form['add_text'] = array(<br />       '#title' =&gt; t('Add a text'),<br />       '#type' =&gt; 'checkbox',<br />       '#default_value' =&gt; $this-&gt;options['add_text'],<br />     );</code></p> <p><code>    parent::buildOptionsForm($form, $form_state);<br />   }</code></p> <p><code>  /**<br />    * {@inheritdoc}<br />    */<br />   public function submitOptionsForm(&amp;$form, FormStateInterface $form_state) {</code></p> <p><code>    $this-&gt;options['add_text'] = $form_state-&gt;getValue('add_text');</code></p> <p><code>    parent::buildOptionsForm($form, $form_state);<br />   }</code></p> <p><code>  /**<br />    * {@inheritdoc}<br />    */<br />   public function adminSummary() {<br />     return $this-&gt;options['add_text'] ? "With text" : "no text";<br />   }</code></p> <p><code>  /**<br />    * {@inheritdoc}<br />    */<br />   public function render(ResultRow $values) {</code></p> <p><code>    return ($this-&gt;options['add_text'] ? "Random value is : " : "") . rand(0, 1000);<br />   }</code></p> <p><code>}</code></p> <p> </p> <h2>Finally</h2> <p><strong>Now you can add this field to your Node, Taxonomy and Users Views.</strong></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/module" hreflang="en">Module</a></li> <li><a href="/en/tags/views" hreflang="en">Views</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/132/views-custom-tables-hook-views-data" hreflang="en">Views with custom Tables - hook_views_data</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=293&amp;2=comment&amp;3=comment" token="a4c14b10"></drupal-render-placeholder> </section> Fri, 03 Mar 2017 12:53:38 +0000 editor 293 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/293/create-a-view-plugin-without-using-database-field#comments Override 40x System error pages on Drupal 8 http://drupal8.ovh/en/tutoriels/292/override-40x-system-error-pages-on-drupal-8 <span class="field field--name-title field--type-string field--label-hidden">Override 40x System error pages 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 override 401, 403 and 404 error pages 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">Mon, 02/20/2017 - 16:31</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>You have several mthodes to override 403 / 404 System pages.</p> <h2>Method 1. Set 403 / 404 pages.</h2> <p>You can set the 403 /404 page on "Basic site settings" page<br /> Admin -&gt; Configuration -&gt; System -&gt; Basic site settings<br /> Path /admin/config/system/site-information</p> <h2>Method 2. Override system 40x Pages (/system/404 ...)</h2> <p>Step 1. <a href="/en/tutoriels/3/create-a-simple-module-for-drupal-8">Create a custom module</a> (Here : 'mymodule').</p> <p>Step 2. <a href="/en/tutoriels/5/create-a-simple-module-for-drupal-8-step-2-create-simple-page">Create a basic page</a> (Here : \Drupal\mymodule\Controller\MyErrorPage:on404).</p> <p>Step 3. Add routing.yml file (Here : mymodule.routing.yml).<br /> Example:<br /><code>mymodule.system.404:<br />   path: '/system/404'<br />   defaults:<br />     _controller: '\Drupal\mymodule\Controller\MyErrorPage:on404'<br />     _title: 'Page not found - 404'<br />   requirements:<br />     _access: 'TRUE'</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> </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/5/create-a-simple-module-for-drupal-8-step-2-create-simple-page" hreflang="en">Create a simple module for Drupal 8 - Step 2 - Create Simple Page</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=292&amp;2=comment&amp;3=comment" token="05f8cffe"></drupal-render-placeholder> </section> Mon, 20 Feb 2017 15:31:32 +0000 editor 292 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/292/override-40x-system-error-pages-on-drupal-8#comments Avoid email send by Php/Drupal mark as spam http://drupal8.ovh/en/tutoriels/291/avoid-email-send-by-php-drupal-mark-as-spam <span class="field field--name-title field--type-string field--label-hidden">Avoid email send by Php/Drupal mark as spam</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 avoid an email send with drupal php mark as a junk mail ?</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">Mon, 02/13/2017 - 12:19</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>An email is classified as spam or not spam on the receiving end, not the sending end. But you can improve</p> <p> Use email authentication methods, such as SPF, and DKIM to prove that your emails and your domain name belong together, and to prevent spoofing of your domain name. The SPF website includes a wizard to generate the DNS information for your site.</p> <p>Check your reverse DNS to make sure the IP address of your mail server points to the domain name that you use for sending mail.</p> <p>Make sure that the IP-address that you're using is not on a blacklist</p> <p>Make sure that the reply-to address is a valid, existing address.</p> <p>Use the full, real name of the addressee in the To field, not just the email-address (e.g. "John Smith" &lt;john@yourdomain.com&gt; ).</p> <p>Monitor your abuse accounts, such as abuse@yourdomain.com and postmaster@yourdomain.com. That means - make sure that these accounts exist, read what's sent to them, and act on complaints.</p> <p>Finally, make it really easy to unsubscribe. Otherwise, your users will unsubscribe by pressing the spam button, and that will affect your reputation.</p> <p>That said, getting Hotmail to accept your emails remains a black art.</p> <p> Add DKIM on Postfix / ubuntu</p> <p>Tutorial : https://help.ubuntu.com/community/Postfix/DKIM</p> <p> Tips for a server using Debian/Ubuntu and Virtualmin.</p> <p>Add DKIM (DomainKeys Identified Mail) from Virtualmin</p> <p>Active / Install DomainKeys Identified Mail (DKIM) from virtualmin<br />     Virtualmin -&gt; Email messages -&gt; DomainKeys Identified Mail<br />     - Install if not already done.<br />     - Set 'Selector for DKIM record name' Example : 'email'<br />     - Add or Exclude domains<br />     - Then add public key shown on 'DNS records for additional domains' to your DNS.</p> <p> Configure the domain to use in outbound mail (Postfix Mail Server)</p> <p>- If you want to use a single domain name for all virtual servers, set it on  /etc/mailname<br /> - Configure domain on:<br />     Webmin -&gt; Servers -&gt; Postfix Mail Server -&gt; General Options</p> <p>Configure DNS for DKIM</p> <p>Selector : Example :  selector._domainkey.yourdomain.com</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/php" hreflang="en">PHP</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=291&amp;2=comment&amp;3=comment" token="3dc3448d"></drupal-render-placeholder> </section> Mon, 13 Feb 2017 11:19:58 +0000 editor 291 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/291/avoid-email-send-by-php-drupal-mark-as-spam#comments Render a Render array to HTML code. http://drupal8.ovh/en/tutoriels/290/render-a-render-array-to-html-code <span class="field field--name-title field--type-string field--label-hidden">Render a Render array to HTML code.</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 HTML from drupal 8 renderer array ?<br /> How to convert Render array into HTML output code ?</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, 02/10/2017 - 21:16</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Example :</p> <p><code>$result =  array(<br />   '#markup' =&gt; 'Hello. This is my First Page',<br /> );<br /> $renderer = \Drupal::service('renderer');<br /> $html = $renderer-&gt;render($result);</code></p> <p> </p> <h3>Render outside of the Render context:</h3> <p><code>$renderer = \Drupal::service('renderer');<br /> $html = $renderer-&gt;renderPlain($result);<br /> #OR<br /> $html = $renderer-&gt;renderRoot($result);</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/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/100/display-contents-using-drupal8-render-api" hreflang="en">Display contents using Drupal8 Render API</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=290&amp;2=comment&amp;3=comment" token="9cfac063"></drupal-render-placeholder> </section> Fri, 10 Feb 2017 20:16:23 +0000 editor 290 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/290/render-a-render-array-to-html-code#comments Insert a view on a custom page or block http://drupal8.ovh/en/tutoriels/289/insert-a-view-on-a-custom-page-or-block <span class="field field--name-title field--type-string field--label-hidden">Insert a view on a custom page or block</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 add and render a views page or block in a custom page or block 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, 02/10/2017 - 11:55</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>This tutorial show toy how to insert an existing views into a <a href="/en/tutoriels/5/create-a-simple-module-for-drupal-8-step-2-create-simple-page">custom page</a> or <a href="/en/tutoriels/107/create-a-simple-block-programmatically">custom block</a>.</p> <p> </p> <h3>Render a views block.</h3> <p><strong>Example : Show Who's online block</strong></p> <p><code>$view = Views::getView('who_s_online');<br /> if (is_object($view)) {<br />   $view-&gt;setDisplay('who_s_online_block');<br />   $view-&gt;preExecute();<br />   $view-&gt;execute();</code><br /><code>  //$content = $view-&gt;buildRenderable('who_s_online_block');<br />   //$content = $view-&gt;buildRenderable('block', $args);</code><br /><code>  $content = $view-&gt;buildRenderable();<br />   $output[] = $content;<br /> }</code></p> <h3> Render a views page with selected exposed filter.</h3> <p><strong>Example : Show People page with user name's contains 'admin' and has administrator role</strong></p> <p><code>$view = Views::getView('user_admin_people');<br /> if (is_object($view)) {<br />   $view-&gt;setExposedInput([<br />     'role' =&gt; 'administrator',<br />     'user' =&gt; 'admin',<br />   ]);<br />   $view-&gt;setDisplay('page_1');<br />   $view-&gt;preExecute();<br />   $view-&gt;execute();</code><br /><code>  //$content = $view-&gt;buildRenderable('page_1');</code><br /><code>  $content = $view-&gt;buildRenderable();<br />   $output[] = $content;<br /> }</code></p> <p> </p> <p><strong>Few other configurations:</strong></p> <p><code>$view-&gt;setArguments([]);<br /> $view-&gt;setItemsPerPage(10);<br /> $view-&gt;setOffset(5);<br /> $view-&gt;setTitle("A new title");</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/views" hreflang="en">Views</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/5/create-a-simple-module-for-drupal-8-step-2-create-simple-page" hreflang="en">Create a simple module for Drupal 8 - Step 2 - Create Simple Page</a></div> <div class="field__item"><a href="/en/tutoriels/12/create-a-simple-module-for-drupal-8-step-3-create-dynamic-page" hreflang="en">Create a simple module for Drupal 8 - Step 3 - Create Dynamic Page/ Block</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=289&amp;2=comment&amp;3=comment" token="734b86c1"></drupal-render-placeholder> </section> Fri, 10 Feb 2017 10:55:34 +0000 editor 289 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/289/insert-a-view-on-a-custom-page-or-block#comments Load entity dynamicly by entity type on Drupal 8 http://drupal8.ovh/en/tutoriels/288/load-entity-dynamicly-by-entity-type-on-drupal-8 <span class="field field--name-title field--type-string field--label-hidden">Load entity dynamicly by entity type 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 load drupal 8 entity dynamicly by entity type and entity id ?</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, 02/10/2017 - 11:44</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h3>Using entity_load function.</h3> <p>Example:<br /><code>$entity = entity_load($entity_type, $id);</code></p> <h3>Using Entity Manager</h3> <p>Example:<br /><code>$entity = \Drupal::entityTypeManager()-&gt;getStorage($entity_type)-&gt;load($id);</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/entity" hreflang="en">Entity</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=288&amp;2=comment&amp;3=comment" token="d272022f"></drupal-render-placeholder> </section> Fri, 10 Feb 2017 10:44:12 +0000 editor 288 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/288/load-entity-dynamicly-by-entity-type-on-drupal-8#comments