Put Cursor Automatically in the text input area

This should work on both Drupal 7 and drupal 8.  I have tested for drupal 8 and working fine.

$form['textfield'] = array(
  '#type' => 'textarea',
  '#attributes' => array(
  'id' => 'unique-textarea'
  'autofocus' => TRUE,
 ),
);

Jquery way to do it.

$('#unique-textarea').focus();

Remember to put this after complete page load.

Advertisements

Disable Form Submit after click to prevent multiple submissions.

For Drupal 7, Hide Submit Module can be used.

Features of ‘Hide Submit’:

  1. Hide or disable the submit button after it has been clicked
  2. Display a message and/or image while waiting

For Drupal 8, the above module is not present. This piece of code will work.

$form['submit_button'] = array(
  '#type' => 'submit',
  '#value' => 'Save',
  '#attributes' => array(
  'onclick' => 'javascript:var s=this;setTimeout(function()      {s.disabled=true;},1);',
 ),
);

Porting Drupal modules from D7 to D8.

There are hell lot of resources available on web which will help you porting from D7 to D8. There are lot of changes in Drupal 8. Drupal 8 has borrowed some components from symfony. Read following articles about drupal and symfony.

1. http://drupalwatchdog.com/volume-4/issue-1/something-borrowed-something-drupal

2. https://www.acquia.com/resources/podcasts/acquia-podcast-132-drupal-symfony-what-open-source-is-about

I suppose porting module will be a great way to understand drupal 8. So i tried to porting  a module name username_check to drupal 8. Here is the github repo for D8 module and the presentation i created to record all the changes involved in porting the module to D8.

Here are the few resources which i collected and few which i created.which will help you to learn porting.

  1. https://www.drupal.org/update/modules/7/8

  2. https://drupalize.me/blog/201412/adventures-porting-d7-form-module-drupal-8

  3. http://drupalwatchdog.com/volume-4/issue-1/upgrading-your-modules

There are more available on web. Since D8 is still in beta  so you can’t just stick to these blogpost or article, you need to keep exploring.