Drupal 7
more_horiz
close

on 17th December 2018 / by webmaster
What are pseudo-fields? Pseudo field is a field that you can add to any content entity type. For example, you can add a pseudo-field to nodes, taxonomy terms, users, paragraphs, etc. You can hide this field in the UI, but you cannot change it's value, because the content of this field is generated via the code. How to manage Pseudo fields? You're already familiar with the "Manage Fields" and "Manage Display" options provided in Structure > Content Types under the Drupal Admin part of a site. Manage Fields allows you to define Fields and order them by how they should appear in an edit or create form, while Manage Display allows you to order the fields per view mode, like Teaser or Full page view. But you may have also noticed some non-editable fields appear in Manage Display such as the node title or URL redirects. Content editors can hide or show this field in display settings of the entity, but the value of this field can’t be changed from the user interface. This type of field is called ‘Pseudo Field’. Scope of this field This is useful for modules that manage their own data attached to an entity or if you want to expose another modules property via Fields UI. These pseudo fields are typically used to expose entity properties that are not managed by "Manage Fields". So, by using pseudo fields, you get all the benefits that other fields created from the UI have, like drag and drop functionality to control visibility and position, but at the same time you can dynamically generate its content. Pseudo field's value can be any renderable array, means that you can return whatever you want like view, form, block or even another entity. Implementation To attach a pseudo field, you need to implement only two hooks. The following is a simple example showing how to add an extra field to the Field UI and provides an example of one way of inserting the field onto a node. /** * Implements hook_field_extra_fields(). */ function example_field_extra_fields() { $extra['node']['article']['display']['field_extra_field'] = array( 'label' => t('Pseudo field label'), 'description' => t(‘Pseudo field description.'), 'weight' => 0, ); return $extra; } /** * Implements hook_node_view(). */ function example_node_view($node, $view_mode, $langcode) { if ($view_mode === 'full' && $node->type === 'article') { $node->content['field_extra_field'] = array( '#markup' => '<p> This is inserted unless hidden in the field UI.</p>’, ); } } Here I attached a pseudo field named 'field_extra_field' to the Article entity and you can test this easily. Just paste the code in your .module file, flush all caches and go to the following page: "admin/structure/types/manage/article/display" where you can see your new field. Drupal 7 Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 17th December 2018 / by akhila.vn
For upgrading any of your contributed Drupal 7 modules, you just need to follow the few steps shown below. First of all you have to make sure that Drush is installed. If not installed, follow the steps from here. Now install a fresh Drupal 8 in your system using Drush commands or directly download from Drupal.org. You must be aware that Drupal 8 has changed its structure from Drupal 7 in configuration, theming, folder structure etc. So now we can find the contributed and custom modules in the modules folder in the root directory. It is also better to create a contrib folder in modules folder for both DMU (Drupal Module Upgrader) and your Drupal 7 module for migration. And now let's have a look at DMU. Drupal Module Upgrader is a script that scans and upgrades the source code of your Drupal 7 module, it also generates a list of new fixes with information links to Drupal.org as an upgrade-info.html file that will be available in your upgrading module directory. Also note that, this DMU scripts will run using Drush and Composer. Now get into your Drupal 8's contrib folder using the terminal (For example: cd public_html/d8/modules/contrib) and follow the steps : Download DMU using the drush command drush dl drupalmoduleupgrader. For example : xx@xx:~/public_html/d8/modules/contrib$ drush dl drupalmoduleupgrader Project drupalmoduleupgrader (8.x-1.2) downloaded to [success] /home/xx/public_html/d8/modules/contrib/drupalmoduleupgrader. Now get into your Drupal module upgrader folder and install Composer. For example: xx@xx:~/public_html/d8/modules/contrib$ cd drupalmoduleupgrader/ xx@xx:~/public_html/d8/modules/contrib/drupalmoduleupgrader$ composer install Loading composer repositories with package information Installing dependencies (including require-dev) from lock file - Installing cebe/markdown (dev-master f89dc1d) Cloning f89dc1da1fc6823f0286d6cad736a642efd0f59e - Installing phpdocumentor/reflection-docblock (2.0.4) Loading from cache - Installing grom358/pharborist (dev-master 0db9e51) Cloning 0db9e51299a80e95b06857ed1809f59bbbab1af6 - Installing symfony/filesystem (2.6.x-dev 823c035) Cloning 823c035b1a5c13a4924e324d016eb07e70f94735 - Installing symfony/finder (2.6.x-dev 203a10f) Cloning 203a10f928ae30176deeba33512999233181dd28 - Installing mikey179/vfsstream (v1.5.0) Loading from cache - Installing phpunit/php-token-stream (1.4.8) Loading from cache - Installing symfony/yaml (v2.7.4) Loading from cache - Installing sebastian/version (1.0.6) Loading from cache - Installing sebastian/global-state (1.0.0) Loading from cache - Installing sebastian/recursion-context (1.0.1) Loading from cache - Installing sebastian/exporter (1.2.1) Loading from cache - Installing sebastian/environment (1.3.2) Loading from cache - Installing sebastian/diff (1.3.0) Loading from cache - Installing sebastian/comparator (1.2.0) Loading from cache - Installing phpunit/php-text-template (1.2.1) Loading from cache - Installing doctrine/instantiator (1.0.5) Loading from cache - Installing phpunit/phpunit-mock-objects (2.3.7) Loading from cache - Installing phpunit/php-timer (1.0.7) Loading from cache - Installing phpunit/php-file-iterator (1.4.1) Loading from cache - Installing phpunit/php-code-coverage (2.2.3) Loading from cache - Installing phpspec/prophecy (v1.5.0) Loading from cache - Installing phpunit/phpunit (4.8.9) Loading from cache phpdocumentor/reflection-docblock suggests installing dflydev/markdown (~1.0) phpdocumentor/reflection-docblock suggests installing erusev/parsedown (~1.0) sebastian/global-state suggests installing ext-uopz (*) phpunit/php-code-coverage suggests installing ext-xdebug (>=2.2.1) phpunit/phpunit suggests installing phpunit/php-invoker (~1.1) Generating autoload files Get back to your contrib folder and clone your Drupal 7 module to it. You can find its cloning commands from its Drupal.org version control page. Here for example: commerce_techprocess is used as Drupal 7 module for migration. xx@xx:~/public_html/d8/modules/contrib/drupalmoduleupgrader$ cd .. xx@xx:~/public_html/d8/modules/contrib$ git clone --branch 7.x-1.x http://git.drupal.org/project/commerce_techprocess.git Cloning into 'commerce_techprocess'... remote: Counting objects: 23, done. remote: Compressing objects: 100% (22/22), done. remote: Total 23 (delta 6), reused 0 (delta 0) Unpacking objects: 100% (23/23), done. Checking connectivity... done. Get back to your site root directory and enable drupalmoduleupgrader. xx@xx:~/public_html/d8$ drush en drupalmoduleupgrader The following extensions will be enabled: drupalmoduleupgrader Do you really want to continue? (y/n): y drupalmoduleupgrader was enabled successfully. [ok] Now start analysing your module using the upgrader, it will list out the fixes and generate an html info file. xx@xx:~/public_html/d8$ drush dmu-analyze commerce_techprocess --path=modules/contrib/commerce_techprocess/ Indexing...done. Generated a report at [success] modules/contrib/commerce_techprocess//upgrade-info.html After all, you can upgrade your module using the command, xx@xx:~/public_html/d8$ drush dmu-upgrade commerce_techprocess --path=modules/contrib/commerce_techprocess/ Indexing...done. It will automatically create some of the Drupal 8 supporting files (for example: .info.yml, .routing.yml etc) and update some of your module codes, and other main functionalities will be commented and provide a @FIXME comment along with it. So that you can easily findout the necessary fixes that the DMU can't do. Now enable your module and fix the issues in Drupal 8 syntax. Also note that your .info or other Drupal 7 supporting files will be there which can be easily removed after fix(if it has no use) and completely upgrading your module codes. Now test your code. Happy Coding! Drupal 8 Drupal 7 Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 17th December 2018 / by webmaster
To implement push notification for a project, we first created a new custom plugin to push messages into a custom table. When the cron runs, the messages stored in the queue table will be processed and saved to the custom table. For this, create a new directory "push" in message_notify/plugins/notifier/ and use it just like email or sms. The directory may contain 2 files: push.inc MessageNotifierPush.class.php In push.inc, create a plugin with class and view modes $plugin = array( 'title' => t('Push'), 'description' => t('Send Message as notification.'), 'class' => 'MessageNotifierPush', // A notifier must define its own view modes. // Those view modes are later going to be rendered and sent. 'view_modes' => array( 'message_notify_push_body' => array('label' => t('Notify - Push body')), ), ); The MessageNotifierPush.class.php extends MessageNotifierBase class and can be structured as: class MessageNotifierPush extends MessageNotifierBase { public function deliver(array $output = array()) { $notification_text = strip_tags($output['message_notify_push_body']); $message = $this->message; // Get the message object and the notification text and pass it to the custom function return abc_push($message, $notification_text); } } In our custom function, abc_push function will fetch the details of message in the queue table. function abc_push($message, $notification_text) { $wrapper = entity_metadata_wrapper('message', $message); $field_value = $wrapper->{field_name}->raw(); // Rest of the code here... } These field values are then saved to our database table. We can display these field values wherever needed. Drupal Drupal 7 Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 17th December 2018 / by jijimol.john
As part of a project requirement, we needed to notify users whenever an entity got created, updated, rated or reviewed. Drupal's 'message' module fulfils this requirement. We can log and display messages and can even customize the notifier plugins. For creating notification, we need to install the following modules: message message_notify message_subscribe The dependent modules are: Flag Ctools Entity API We can add message types in admin/structure/messages. In message types, we can add fields with the fields type. When the event is triggered, the rule action is processed for the corresponding messages and it will be saved to the queue table. While cron runs, the message notify plugin processes the messages and delivers it. Message notify module provide us with email and sms notifier. Message This module is at the core of message stack. This module help us to create message types. Message subscribe This module helps us to register the notified content when an event is triggered. This messages will get stored in the queue table. For preventing looping of messages in the queue system, apply the following patch to the message_subscribe.module . Message notify This module is used for sending or viewing messages via notifier plugin. Message notifier has 2 default plugins- email and sms. Hope this article helps! Drupal 7 Leave a reply Your email address will not be published. Required fields are marker *
close

on 13th March 2018 / by riyas.nr
Kraftwagen is an Open Source deployment tool which is built entirely on top of Drush. Kraftwagen makes Drupal “easy to use” for developers, who customize Drupal extensively, need staged deployments and use version control systems to collaborate. It provides a set of commands for 'drush make' based Drupal development workflow. Benefits of using Kraftwagen for security updates By using Kraftwagen to deploy security updates, the benefits are multifold, which include Kraftwagen stores configuration as code in version control as opposed to other methods which store it in a database. No need of copying files to project instead refer to external code resources (Drupal core, contrib modules and external libraries). This means that your project repository is very slim. Effective single command deployment to multiple deploy targets (Development, Staging, Production). Deploying Security Updates to Drupal 7 Site Usually deploying security updates to Drupal 7 project can be a painful process. Basic Drupal 7 site update workflow is as follows: Backup database. Backup codebase. Download newer version of modules or make use of drush command drush up. Manually investigate if the modules have been hacked or patched. Then for database changes, run update.php in browser. But with Kraftwagen this whole process becomes easier. All Drupal 7 core and contrib projects are saved by just version number in a .make file. Everything will be downloaded at the time of site building. This itself makes updating process easier since we only need to update version number in our .make file and rebuild the site. Steps to Deploy using Kraftwagen Update version number in .make file. Build site using command drush kw-build. Conclusion So it is very evident that deployment to a Drupal 7 site through Kraftwagen put developers at ease with an otherwise hectic process. This is for more serious developers who crave for some single trigger deployment unlike other file transfer or dashboard based deploy environment. Deploying with Kraftwagen helps keep your git repo simple and slim. Security Updates Drupal 7 Kraftwagen Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 08th January 2018 / by akhila.vn
In one of my work, there was a requirement to uncheck the option for 'Generate automatic url alias' checkbox for all nodes. I used the Pathauto module with version 7.x-1.2 for handling standard urls in the site. When changing a node title, its URL automatically changes. In case one forgets to uncheck the option 'Generate automatic url alias' in the node editing form, you can uncheck the option with the following steps: Go to 'admin/config/search/path/settings' page. In Update action section, select the option 'Do nothing. Leave the old alias intact'. And save the configuration. This way you can uncheck 'Generate automatic URL alias' option for all nodes instead of any form alters. Hope this helps to handle node's urls. Drupal 7 Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 19th December 2017 / by wellme.m
For a recent project, I had a requirement to implement menu tabs in Drupal 7. Let see what are the necessary code for the same. First I created menu tabs in .module file using hook_menu() with the following codes. /** * Implements hook_menu(). */ function MYMODULE_menu() { $items['path']= array( 'title' => t('Create menu tab in your page.'), 'page callback' => 'first_tab', 'access callback' => TRUE, 'weight' => 0, ); $items['path/firsttab'] = array( 'title' => t('Create first tab.'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'page callback' => 'first_tab', 'access callback' => TRUE, 'weight' => 0, ); $items['path/secondtab'] = array( 'title' => t('Create second tab'), 'type' => MENU_LOCAL_TASK, 'page callback' => 'second_tab', 'access callback' => TRUE, 'weight' => 1, ); $items['path/thirdtab'] = array( 'title' => t('Create third tab'), 'type' => MENU_LOCAL_TASK, 'page callback' => 'third_tab', 'access callback' => TRUE, 'weight' => 2, ); return $items; }Then I wrote the necessary page callback functions for the corresponding tabs. /** * First tab. */ function first_tab() { $str = t('Hi this is first tab'); return $str; } /** * Second tab. */ function second_tab() { $str = t('Hi this is second tab'); return $str; } /** * Third tab. */ function third_tab() { $str = t('Hi this is third tab'); return $str; } Similar to the above, you can create more tabs and add other functionalities for each page. Here 'MENU_DEFAULT_LOCAL_TASK' and 'MENU_LOCAL_TASK' in menu type specification is important. The main page tab should be specified as 'MENU_DEFAULT_LOCAL_TASK'. Hope this is useful, contact us for further assistance. Drupal 7 Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 18th December 2017 / by akhila.vn
A patch is a small file which shows what was changed in a repository. It shows the new changes in an existing file, details of the new files in the current directory, file deletion details etc. A patch file can be pushed to the git repository so that it is useful in the future for updating the changes in the corresponding file. For creating a patch file in your current git repository, make changes in your files. Now open the terminal. For unstaged changes, type the following command, git diff > new-changes.patchFor staged changes, you have to use git diff --cached. That is, git diff --cached > new-changes.patchTo apply the patch, use: git apply -v new-changes.patchNote that, if the changes is already there when applying your patch, error message will be shown. In Drupal.org, you can contribute patches to the existing core or contributed modules. For this, First clone the latest version of Drupal (if it is a contributed module clone the latest code from its version control) You have to create the issue with necessary issue summary in Drupal.org based on the fix After making the changes, create a patch file based on the issue number as,git diff > [issue-description]-[issue-number]-[comment-number].patch Update the issue with necessary comment and patch file Make it's status as 'Needs Review' If you want to test the patch file, add it to the queue by clicking the 'Add test' link shown below of the updated patch file We can create and add inter diff for adding new modification for an existing patch file in an issue in Drupal.org, if the changes are not in the latest version of the module. For this, Apply the existing patch to the latest version of module Add your changes to the module Create a new patch from git diff using git diff > [issue-description]-[issue-number]-[comment-number].patch Create an inter diff from the old and new patches as:interdiff old-file.patch new-file.patch > interdiff-[issue_id]-[old_comment_number]-[new_comment_number].txt Upload the newly created patch and the inter diff to the created issue in Drupal.org. An interdiff file tells you what new changes are there with the existing patch and newly created patch. It provides the information of the changes in patch files. So we can make the file as test free using 'do not test' option in the issues itself. So for interdiff to be ignored by the testbot, we can name the interdiff file as: interdiff-[issue_id]-[old_comment_number]-[new_comment_number]-do-not-test.diffHope this information helps in your patch creation. Drupal 7 Drupal 8 Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 13th December 2017 / by fazeela.ma
To render a Drupal form to a node, drupal_build_form function is used. This function allows us to render all forms except the admin forms. Note that, admin forms didn't find success while rendering the same. In-order to render a form the following syntax is used, $form_id = 'user_login_form'; $form_state = array(); $form_state['build_info']['args'] = array(); $form_state['build_info']['files']['menu'] = array(); $form = drupal_build_form($form_id, $form_state); return render($form); }Here we are trying to render user login form, if you are logged in as a user it will redirect to user profile page. Here form state values are built and are passed as parameter along with form id for the drupal_build_form function. Instead of drupal_render(), simply render() is used to render. This will output the form in the node page. Hope this help, happy coding. For more assistance, contact us and for Drupal solutions, have a look on our services. Drupal 7 Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 06th December 2017 / by thomas.john
In this article I will be explaining how to create a custom media gallery functionality using the library Fancybox. First step is to create the content type 'Media Gallery(media_gallery)' and add the following fields in page 'admin/structure/types/manage/media_gallery/fields' Title : Text field Media Gallery Image(field_media_gallery_image) : Image field In manage display page admin/structure/types/manage/media_gallery/display of the content type, select an image style or create the required style from the image style setting page admin/config/media/image-styles/add and link the image to the file. Create a tpl file for the content type 'Media Gallery' and rename it as 'node--media_gallery.tpl.php', you can refer Drupal 7 node.tpl.php.. In our tpl file hide or remove variable $content, so that we can customise our images later. Get the count of images and store it to variable $image_count (for example). Add the following code to the tpl file, here for each image we are adding a tag, with class name 'fancybox' to invoke the fancybox styles and title 'node title' to display the title name. For each image we are displaying the count as well. <?php // We hide the content now so that we can render them later. hide($content); // Get the number of images in that node $image_count = count($node->field_media_gallery_image['und']); for ($i = 0; $i < $image_count; $i++) { //Create image URL. $image_uri = $node->field_media_gallery_image['und'][$i]['uri']; $image_style = image_style_url('ckg_gallery_medium', $image_uri); ?> <a href="<?php print file_create_url($node->field_media_gallery_image['und'][$i]['uri']); ?>" rel="group-<?php print $node->nid; ?>" class="fancybox" title="<?php print $node->title; ?>"> <img class="image<?php print ($i + 1);?>" src="<?php print $image_style; ?>" /> </a> <?php } ?>Create a view page to list all the galleries and display one image from each gallery. See the attached screen-shot below. When a user click on the image takes them to gallery inner page, where all the images will be listed. See the attached screen-shot below. To implement the Fancybox feature download the latest files from fancybox.net. Extract the all the files and create a folder 'fancybox' in path 'sites/all/libraries/'. Move all the images and following files 'jquery.easing-1.3.pack.js', 'jquery.fancybox-1.3.4.css', 'jquery.fancybox-1.3.4.js', 'jquery.fancybox-1.3.4.pack.js' and 'jquery.mousewheel-3.0.4.pack.js' to folder 'fancybox'. In template.php file use the function template_process_page to add the required CSS and JS files. /** * Override or insert variables into the page template. */ function template_process_page(&$vars) { /*Fancybox plugin for media gallery*/ if (isset($vars['node'])) { if ($vars['node']->type == 'media_gallery') { drupal_add_js(libraries_get_path('fancybox') . '/jquery.mousewheel-3.0.6.pack.js'); drupal_add_js(libraries_get_path('fancybox') . '/jquery.fancybox-1.3.4.pack.js'); drupal_add_css(libraries_get_path('fancybox') . '/jquery.fancybox.css'); /*Create a custon js file to display fancybox*/ drupal_add_js(drupal_get_path('theme', 'theme_name') . '/js/media-gallery.js'); } } }Create a custom JS file 'media-gallery.js' to process which all features should be implemented while displaying the images. (function ($) { $( document ).ready(function() { $('.fancybox').fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' : 'inside', 'titleFormat' : function(title, currentArray, currentIndex, currentOpts) { return 'Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? '   ' + title : '') + ''; } }); }); })(jQuery);Now when a user clicks on the image from gallery page it will be displayed and shown in the screen shot below. Hope this helps. Drupal 7 Fancybox Leave a reply Your email address will not be published. Required fields are marker *