Drupal Planet
more_horiz
close

on 06th July 2017 / by webmaster
Authors: Adrian McDonald Tariang, Anish M.M. Drupal 8 Render Pipeline is the sequence of steps through which Drupal 8 generates a response to an HTTP request. ie, it’s what’s going on under the hood of Drupal 8. As summer interns, we were trying to understand this process. While going through online material available on the topic, we noted that almost half of it was aimed at people transitioning from Drupal 7 to Drupal 8. Newbies as were to Drupal, we did struggle to figure it out. While digging through the material, it is quite easy to be misled and arrive at wrong conclusions. So, we have come up with this presentation, which targets beginners and keeps it as simple as possible. This presentation is a walk through of the steps followed by Drupal 8 between getting a request and sending back the corresponding response, in that order, with specific details and examples mentioned when deemed necessary. It will provide an overview of the whole process, with emphasis on the Event Mechanism and the Routing Process. The presentation will, we hope, give you a broad understanding of the topic and give you pointers on areas to focus. You are encouraged to follow up on this presentation by going through the references mentioned at the end. We cannot emphasize enough the benefits of going through the code, and urge you to download Drupal 8 code and go through it. A little bit of tweaking in there can go a long way in getting to know the concepts. The online documentation of the code will also come in handy. Few of the tools you could use the blackfire.io or the XHProf profiler, can help in understanding Drupal’s routing system and dependency model debug_backtrace() for local system debugging. The devel module also provides a ddebug_backtrace() that provides a more readable output Learn Drupal 8 Render Pipeline from Zyxware Technologies In Brief Drupal 8 adopts most of its functionality from the Symfony Framework to implement modern PHP standards and is a platform for more developers to enter the Drupal Community. Front Controller The journey begins at the Front Controller, the index.php file, a construct that serves as an entry and exit point for all communications with Drupal. This is where Drupal wraps the request from the user into a Symfony Response Object for a more object oriented approach for request handling. The Request object is then passed through Symfony’s HttpKernel::handle() method, the backbone of the render pipeline that uses an event-based architecture to delegate the task at hand. This system makes Drupal easily extensible, as Developers can now create their own Subscribers to events and modify the end response. Drupal 8 uses the concept of a Controller, a section of code which performs the main application logic. The Controller is assigned through a process called Routing, where, each path( say /admin), is mapped to its corresponding controller. Response The Controller returns its results in the form of a Response object, ready to be sent back to the user, or a classic Drupal Render Array. This Render Array is then pushed to the MainContentViewSubscriber, which decides how the array is to be converted into the Response object. This process, called Rendering, is performed by a Content Renderer, based on the format the response needs to be sent in. Now, when a Response Object is received, Drupal prepares placeholders present on it’s HTML, so as to allow them to be replaced with content by popular placeholder strategies such as ESI, Big Pipe or SingleFlush, after which the final headers and assets are attached to the Response. This Response is then sent back to the user, completing its journey through the Render Pipeline. Credits Wim Leers, author to material such as the render pipeline diagram and the DrupalCon Los Angeles 2015: Drupal 8's render pipeline session. These were extensively referred to for this presentation. References: Site Point: From Request to ResponseDrupal Render API DocumentationDrupal 8 Render Pipeline talkSymfony 2 HttpKernel ComponentDrupal API Documentation Drupal 8 Drupal Planet Symfony Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 05th September 2016 / by wellme.m
In Drupal 8, third party libraries are downloaded and managed via composer. In Drupal each project must contain only one vendor folder. Composer Manager allows single vendor/directory shared across all modules which prevents code duplication and version mismatches by merging the requirements of all the found modules into the consolidated composer.json file. In custom module, set dependency for composer manager module in .info file. dependencies: - composer_managerWrite composer.json file for your custom module to download php library dependency. Your composer.json file should contain at least name and requirement (your php library). { "name": "drupal/mymodule", "require": { "endroid/qrcode": "^1.6" } } Following are the steps to work custom modules with composer.json : 1. First of all install Composer Manager module. 2. In your Drupal root directory, run the module's init.php script on the command line. For example, username@locahost:/var/www/SITENAME$ php modules/contrib/composer_manager/scripts/init.php 3. In command line, you will see the message after step 2 as 'Composer Manager has been successfully initialized', once initialized properly. Now run composer drupal-update from the root of your Drupal site directory. For example, username@locahost:/var/www/SITENAME$ composer drupal-update composer update After the above three steps, the php library is downloaded to the vendor folder in Drupal root directory. Now you can see the composer manager module status in /admin/reports/composer. If you want to download the dependency library in a specified folder path, then set path in your composer.json file. "config": { "vendor-dir": "includes" } Hope this helps. Also, please feel free to get in touch with us for any queries. Drupal Drupal 8 Drupal Planet Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 24th August 2016 / by jimmy.sebastian
This article covers, how to send email programmatically in your Drupal 8 site. There are two main steps to send an email using Drupal 8. First we need to implement hook_mail() to define email templates and the second step is to use the mail manager to send emails using these templates. Let's see an example for sending an email from the custom module, also the following name spaces. use Drupal\Core\Mail\MailManagerInterface; use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Html; /** * Implements hook_mail(). */ function module-name_mail($key, &$message, $params) { $options = array( 'langcode' => $message['langcode'], ); switch ($key) { case 'node_insert': $message['from'] = \Drupal::config('system.site')->get('mail'); $message['subject'] = t('Your mail subject Here: @title', array('@title' => $params['title']), $options); $message['body'][] = Html::escape($params['message']); break; } } Here, the variables $key, $message and params can be described as : $key: An identifier of the mail template. $message: An array to be filled in. Elements in this array include: id, to, subject, body, from, headers $params: An array of parameters supplied by the caller of drupal_mail(). Now lets create a custom function to send the mail using mail manager. function custom_function_name() { $mailManager = \Drupal::service('plugin.manager.mail'); $module = 'module-name'; $key = 'node_insert'; // Replace with Your key $to = \Drupal::currentUser()->getEmail(); $params['message'] = $message; $params['title'] = $label; $langcode = \Drupal::currentUser()->getPreferredLangcode(); $send = true; $result = $mailManager->mail($module, $key, $to, $langcode, $params, NULL, $send); if ($result['result'] != true) { $message = t('There was a problem sending your email notification to @email.', array('@email' => $to)); drupal_set_message($message, 'error'); \Drupal::logger('mail-log')->error($message); return; } $message = t('An email notification has been sent to @email ', array('@email' => $to)); drupal_set_message($message); \Drupal::logger('mail-log')->notice($message); } Hope this helps, also checkout how to configure SMTP in Drupal 8 using swiftmailer Module Drupal Drupal 8 Drupal Planet Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 19th August 2016 / by jimmy.sebastian
In one of my Drupal 8 work I needed to configure SMTP using swiftmailer Module. The module extends the basic mail sending functionality which is provided by Drupal by delegating all mail handling to Swift Mailer library. This library provides features, such as : Sends e-mails directly through an SMTP server of our choice, that is a locally installed MTA agent such as sendmail or the mail functionality which is provided by PHP. Sending HTML e-mails(MIME). Adds file attachments along with mails. Adds inline images to e-mails. The Swift Mailer module depends on the mailsystem module which is responsible for making the Swift Mailer module available to Drupal. You have to install SwiftMailer Library before enabling swiftmailer module. The preferred way to install Swiftmailer is via Composer. Use the following command for this: $ composer require swiftmailer/swiftmailerOnce the module is installed, you can set Drupal to use swiftmailer as default mail system to send HTML mails with the following settings. Configure Mail System Configure the Mail System page (admin/config/system/mailsystem) to Global Mail System configuration. Configure SwiftMailer Settings Go to the Mail System page (admin/config/swiftmailer/transport) to configure Swift Mailer transport and message settings. For more details click here Drupal Drupal 8 Drupal Planet Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 08th August 2016 / by hari.venu
In Drupal 7 we can upgrade a module in many ways but we fail on upgrade feeds excel module. The reason being the newer version of the module is entirely different from the old version folder structure and file naming. We can overcome this situation by uninstalling the older version and installing the new version. Sometimes we cannot uninstall the module due to the module dependency and data lock. We can achieve this manually using the following steps. STEP 1. Remove/delete library phpExcelReader (Which is not required Feeds Excel 7.x-2.x) . STEP 2. Upgrade library PHPExcel older version to version 1.8 or greater. Download this from github https://github.com/PHPOffice/PHPExcel/archive/1.8.zip). STEP 3. Upgrade module phpexcel older version to 3.11. Download this from Drupal module (https://www.drupal.org/project/phpexcel). STEP 4. Upgrade modules Libraries (https://www.drupal.org/project/libraries) and Feeds (https://www.drupal.org/project/feeds) to latest version. STEP 5. Replace older folder of feeds excel with feeds excel 7.0-2.x (https://www.drupal.org/node/2678690) by manually copy and replace. STEP 6. Now we will get some PHP fatal errors, so you should truncate the Drupal cache table manually. If you have cpanel environment go to the phpmyadmin then truncate it. STEP 7. Re-configure existing feeds importers (siteurl/admin/structure/feeds). Not support older importer configuration in the newer version. STEP 8. Finally clear the cache. Happy coding. If you need any further assistance please feel free to get in touch with us Drupal Drupal 7 Feeds Drupal Planet Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 21st July 2016 / by akhila.vn
In Drupal 8, variable_set() and variable_get() is deprecated. The variables database table in Drupal 7 is now removed in Drupal 8, and is replaced with config table. We can create a variable while installing the module using MODULE.setting.yml and MODULE.schema.yml files. We can configure default values in MODULE.setting.yml file and the storage type will be defined in MODULE.schema.yml. The setting file should be stored as MODULE/config/install/MODULE.setting.yml and the schema as MODULE/config/schema/MODULE.schema.yml. There are two types of configuration schema config_object for global configuration and config_entity for entities. Simple example for variable configuration in Drupal 8 is as follows: MODULE.schema.yml mymodule.settings: type: mapping label: Variable Settings of My Module mapping: variable_one: type: string variable_two: type: email variable_three: type: boolean MODULE.settings.yml variable_one: 'Sample Content' variable_two: '' variable_three: true We can get the configured objects as: $config = \Drupal::config('mymodule.settings'); $variable_one = $config->get('variable_one'); We can edit the configuration as, $config = \Drupal::service('config.factory')->getEditable('mymodule.settings'); $config->set('variable_one', 'New Value') ->set('variable_two', FALSE) ->save(); Hope you find this article useful. Also, if any queries please feel free to get in touch with us. Drupal 8 Drupal Planet Leave a reply Your email address will not be published. Required fields are marker *
close

on 20th April 2016 / by varokky.jose
One of our project requirement was to transfer files from our server to an external storage space. This could be basically done by connecting to the server using SSH or FTP and then transferring files. We initially decided to use the libssh2-php library for creating SSH tunneling with the server and transfer file. Our server was hosted in Acquia server and libssh2-php was not available in Acquia stack. Read on to know how we tackled the problem of file transfer to an external storage space in Acquia environment. Since libssh2-php could not be installed in Acquia server, we looked for alternatives for transferring files to an external source. phpseclib library suited our requirement as it does not require any extension and provides SSH as well as SFTP connection. Have a look at the following code to establish connection and transfer files. function mymodule_amazon_connect() { require_once 'Net/SFTP.php'; $file_contents = file_get_contents('myfile.txt', TRUE); // Setup connection. $sftp = new Net_SFTP('www.mydomain.com'); if (!$sftp->login('username', 'password')) { exit('Login failed!'); } $sftp->put('myfile.txt', $file_contents); } Hope this helps. Also, if you need any further assistance please feel free to get in touch with us Acquia Hosting Drupal Planet Leave a reply Your email address will not be published. Required fields are marker *
close

on 14th April 2016 / by webmaster
We have been involved with the Drupal Open Curriculum initiative under the Curriculum and Training group in groups.drupal.org for the last few months and have been helping build up the content for the initiative. One of the important pieces of content that is expected to be developed as part of this initiative is the question bank with objective type questions that can be used to evaluate the progress of the training of Drupal developers. Significant progress has been made on the build up of the question set. The project has been getting feedback and inputs from the community and they have been incorporated into the curriculum. There is a lot of work that is to be done to get this to completion though and we are expecting more people to chip in with contributions. The questions are being compiled in a google document and you can access this question bank here. The questions are created as multiple choice questions (MCQs) so that this can easily be set up in any LMS as Drupal tests. Once the Open Curriculum project delivers on its objectives, we believe that we will have a quality repository of content which can readily be consumed by new recruits in Drupal companies to help in their rapid training and deployment. This should in turn help faster adoption of Drupal by companies and help ensure a healthy volume of competent Drupal developers in the market. We are one of the leading Drupal development companies in India. We offer Drupal development offshore services and are experts in our domain. To know more please get in touch with us. Drupalgive Drupal Training Drupal Planet Teaching Drupal News Leave a reply Your email address will not be published. Required fields are marker * Jonathan Shaw (not verified) access_time 27 Mar 2019 - 03:53 Your shortlink to the question bank is broken Add new comment
more_horiz
close

on 05th April 2016 / by Anoop John
We are happy to inform that, we have completed the the first phase of the project on creating a standardized Drupal curriculum for Drupal companies as planned. We have compiled and published our Drupal training curriculum on the groups.drupal.org wiki under the Curriculum and Training group. We are now looking to get feedback from other Drupal companies and Drupal developers on the curriculum and the training materials. We also would like to invite developers from the community to contribute towards making this curriculum better. The curriculum is available under the Curriculum and Training group. Drupal groups wiki is kind of difficult to navigate on its own. We have created a table of contents for all the contents published under this project. You can access the table of contents at https://groups.drupal.org/node/508323 We had originally announced that we will be publishing the content under GFDL but as per recommendations from Donna Benjamin and Dave Hall we are publishing this under CC-by-SA In the course of compiling and publishing the content we have realized that there is quite a lot that the trainers teach the developers from their experience and not necessarily directly from the training content. So there is still a lot of work to be done on the curriculum but we belie ve that the published curriculum is a good beginning. We believe learning Drupal is not a one time process and it requires continuous effort from the developer. The curriculum has been designed to help a PHP developer become a competent Drupal developer well versed in the different areas in Drupal and different aspects of Drupal development over a period of one year. There is a bit of effort required to build a comprehensive question bank to evaluate the progress of developers in this journey and we are hoping that we will be able to get some inputs from the community on this. We are now looking to publish and make available all of this content under a Moodle instance with public access so that developers or other Drupal companies can evaluate the content under a proper course perspective and contribute towards improving this. We would like to thank all those in the community who have contributed towards the effort so far and would like to invite more people to come join this initiative. Drupal Drupalgive Drupal Planet Drupal Training Teaching Drupal News Announcements Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 08th March 2016 / by premshankar.pb
A Payment gateway tends to offer multiple types of payment services, that provides onsite and offsite options. Onsite payment is processed by a third party API using web services with the information gathered from our site through a checkout form (For example : Credit card/Debit card credentials). Offsite payment method, on the other hand, processes data entered in the payment gateway page. It redirects the users to the processing page of the payment gateway using the checkout form. After the payment is completed, the user will be redirected to the payment page, from where the user can move forward or backward in the checkout process. Here, let's take a look at the creation of custom offsite payment gateway module. Creating Payment method For creating a payment method, we should define a method using the hook_commerce_payment_method_info(). function hook_commerce_payment_method_info() { $payment_methods = array(); $logo_url = drupal_get_path('module', 'custom') . '/images/techprocess_logo.png'; $display_title = t('!logo payment gateway', array('!logo' => '<img width="172" height="61" src=' . "/$logo_url" . '>')); $payment_methods['payment_method_name'] = array( 'base' => 'base', 'title' => t('title'), 'short_title' => t('short tile'), 'display_title' => $display_title, 'description' => t('payment details'), 'terminal' => FALSE, 'offsite' => TRUE, 'offsite_autoredirect' => TRUE ); return $payment_methods; }Here the parameters offsite is set to true; this means that the payment method is meant for offsite payment. You can find all the supporting parameters from the link Payment info hooks. Set the module dependencies Add the dependencies for modules: Commerce, Commerce UI, Commerce Payment, Commerce Order. Add the below code to your info file. dependencies[] = commerce dependencies[] = commerce_ui dependencies[] = commerce_payment dependencies[] = commerce_order Enable the payment method When you declare a payment method, you should enable the payment method. Go to 'admin/commerce/config/payment-methods' and enable the method. set up configuration form For offsite payment method, you should have to use the key sets provided by the payment service provider with which the payment call is done. Create an admin/config form to save this values as system variables. Redirect form function(base_redirect_form()). This is the hook function that will call when we click the make payment function. We can put the custom function for making payment inside this hook. Redirect form validate function(base_redirect_form_validate()). This is the hook function that will call when the payment is completed and redirected to our site. Here, we can check the status of the transactions. Most of the offsite payment services provides the second verification for a completed transaction. On success, it will return false, which will go to the success page. Currently, we are contributing the 'Tech-process payment module' to Drupal. This is one of the simplest offsite payment drupal modules. If you need any further assistance, please feel free to get in touch with us. Drupal Drupal 7 Payment Gateway Integration Drupal Planet Leave a reply Your email address will not be published. Required fields are marker * Josh Smith (not verified) access_time 27 Mar 2019 - 04:04 The best shop module to use of Drupal 7 is 'Light Shop'https://www.drupal.org/project/lightshop Add new comment