Ryan Szrama: Deadline drawing near for Pitch-burgh entries

You have a little more than two days to submit a proposal for DrupalCon Pittsburgh's innovation grant contest dubbed "Pitch-burgh." The Drupal Association has raised $75,000+ to allocate to the most compelling proposals received by May 25th. There is no lower limit on proposal size. A $1,000 "quick fix" is just as valid as a $20,000 proposal. Additionally, entrants can be individuals or companies. The only criteria is that pitches contribute to Drupal's continued innovation, whether through code, design, documentation, or even contribution process improvements. Read more

CTI Digital: Gain Competitive Advantage and Accelerate Your Drupal Build

Image removed.

When it comes to upgrading your website, the decision is never taken lightly. 

It's a process that demands considerable effort, time, and money.

Whether aiming to boost your CMS platform's performance or enhance the user experience, making sure you choose the upgrade that delivers the greatest value for your investment is crucial.

We understand this better than anyone else as one of Europe's most experienced Drupal development agencies. Our expertise in Drupal allows us to streamline the installation process, getting you started on your priority features quickly and cost-effectively.

But that's not all. We've developed something truly special: Drupal Accelerator. 

This innovative tool is designed to fast-track the installation of Drupal, providing you with a cost-effective package to create highly effective and efficient content and marketing websites. It harnesses the power of commonly used, ready-to-go features and functionalities, making it the perfect solution to fast-track the build and focus on your specific needs.

Image removed.

Specbee: How to Adhere to Drupal Coding Standards with Git Hooks

How to Adhere to Drupal Coding Standards with Git Hooks Prabhu 23 May, 2023 Subscribe to our Newsletter Now Subscribe Leave this field blank

Good code is like well-built Lego creations - it's strong, looks good, and is easy to change if you need to. The importance of good coding standards is especially high when you're coding in a team, working on a scalable project, or participating in an open-source community like Drupal.  

As with any other open-source project, Drupal has thousands of developers working on the project. And each of them comes with their own level of expertise. How do you ensure everyone on your team or in the community follows good coding practices? Git Hooks!

Git Hooks are an easy and automated way of ensuring your code always meets Drupal’s coding standards. Implementing Drupal Coding Standards with Git hook will help developers to commit and push the code with proper coding standards as declared by the Drupal community. It can also help improve your project management skills and allows developers to commit code with proper commit message standards. Learn more about Git hooks and how to put them into action.

Image removed.

What is a Git Hook

Git Hooks are scripts that will run automatically every time a Git command is invoked. Just as you would use hook_form_alter to alter the forms in Drupal, you can have separate pre-defined hooks for every Git action.

Image removed.

The Pictorial Representation of Git hook

Finding Git hooks

You can find Git hooks within your project folder (provided Git is initialized) under .git/hooks.  There, you will find all the hooks with .sample extension to prevent them from executing by default.

To make use of the required hooks, you need to remove the .sample extension and edit your code for the execution.

There are many Git hooks available but we are going to use pre-commit Git hooks for initiating Drupal coding standards. 

Pre-commit Git hooks are hooks that will run before the code gets committed. It checks for the line of code that's getting committed.

Implementing Git Hooks

Before you start, make sure you have these basic requirements ready:

  • Composer
  • Git
  • Php-code-sniffer
  • drupal/coder:8.3.13

The below procedure is for installing it in Mac devices. You can find the reference link here for installing instructions on other devices.

  • brew install php-code-sniffer
  • composer global require drupal/coder:8.3.13
  • phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer
  • phpcs -i  → Will give you installed coding standards.

Let's begin!

I am creating a new Drupal project called demo. You can use it in your existing project as well.

Image removed.

 

→ Using cd command we got into the project folder.
     cd demo

→ initializing git into the project
    Git init

→ Adding and making my first commit.
    git commit -m “Initial commit”

Image removed.

 

→ Installing php code sniffer using below command for Mac.
    brew install php-code-sniffer

Image removed.

 

→ Installing Drupal coder using composer
composer global require drupal/coder:8.3.13

→ Once the coder and its path are defined you will get the following output as shown below image. 
phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer

→ phpcs -i
The above command will give you Drupal and DrupalPractice

Image removed.

→ Now you can commit your code. If you have any syntax or coding standard error, you will be notified in the display and your commit process will be aborted.

Image removed.

→ Below is the code to fix the error automatically

phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml web/modules/custom/demo

Any other issues will need to be fixed manually. Commit your code once done.

Image removed.

Once your code is clean it will allow you to commit the code

Image removed.

Just copy and paste the code in pre-commit.sample within .git/hooks. Don’t forget to remove sample extensions.

Pre-commit code sample:

#!/bin/bash

# Redirect output to stderr.

exec 1>&2

# Color codes for the error message.

redclr=`tput setaf 1`
greenclr=`tput setaf 2`
blueclr=`tput setaf 4`
reset=`tput sgr0`

# Printing the notification in the display screen.

echo  "${blueclr}"
echo "................................. Validating your codes  ……..…………....."
echo "-----------------------------------------------------------${reset}"

# Mentioning the directories which should be excluded.

dir_exclude='\/kint\/|\/contrib\/|\/devel\/|\/libraries\/|\/vendor\/|\.info$|\.png$|\.gif$|\.jpg$|\.ico$|\.patch$|

\.htaccess$|\.sh$|\.ttf$|\.woff$|\.eot$|\.svg$'

# Checking for the debugging keyword in the commiting code base.

keywords=(ddebug_backtrace debug_backtrace dpm print_r var_dump  dump console\.log)

keywords_for_grep=$(printf "|%s" "${keywords[@]}")
keywords_for_grep=${keywords_for_grep:1}

# Flags for the counter.

synatx_error_found=0
debugging_function_found=0
merge_conflict=0
coding_standard_error=0

# Checking for PHP syntax errors.

changed_files=`git diff-index --diff-filter=ACMRT --cached --name-only HEAD -- | egrep '\.theme$|\.module$|\.inc|\.php$'`
if [ -n "$changed_files" ]
then
  for FILE in $changed_files; do
  php -l $FILE > /dev/null 2>&1
  compiler_result=$?
  if [ $compiler_result -eq 255 ]
  then
    if [ $synatx_error_found -eq 0 ]
    then
      echo "${redclr}"
      echo "# Compilation error(s):"
      echo "=========================${reset}"
    fi
    synatx_error_found=1
    `php -l $FILE > /dev/null`
  fi
  done
fi

# Checking for debugging functions.

files_changed=`git diff-index --diff-filter=ACMRT --cached --name-only HEAD -- | egrep -v $dir_exclude`
if [ -n "$files_changed" ]
then
  for FILE in $files_changed ; do
    for keyword in "${keywords[@]}" ; do

      pattern="^\+(.*)?$keyword(.*)?"
      resulted_files=`git diff --cached $FILE | egrep -x "$pattern"`
      if [ ! -z "$resulted_files" ]
      then
        if [ $debugging_function_found -eq 0 ]
        then
          echo "${redclr}"
          echo "Validating keywords"
          echo "================================================${reset}"
        fi
        debugging_function_found=1
        echo "Debugging function" $keyword
        git grep -n $keyword $FILE | awk '{split($0,a,":");
          printf "\found in " a[1] " in line " a[2] "\n";
        }'
      fi
    done
  done
fi

# Checking for Drupal coding standards

changed_files=`git diff-index --diff-filter=ACMRT --cached --name-only HEAD -- | egrep -v $dir_exclude | egrep '\.php$|\.module$|\.inc$|\.install$|\.test$|\.profile$|\.theme$|\.js$|\.css$|\.info$|\.txt$|\.yml$'`
if [ -n "$changed_files" ]
then
    phpcs_result=`phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml --report=csv $changed_files`
  if [ "$phpcs_result" != "File,Line,Column,Type,Message,Source,Severity,Fixable" ]
  then
    echo "${redclr}"
    echo "# Hey Buddy, The hook found some issue(s)."
    echo "---------------------------------------------------------------------------------------------${reset}"
    phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml $changed_files
    echo "<=======> Run below command to fix the issue(s)"
    echo "# phpcbf --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml your_custom_module_or_file_path"
    echo “<====================================================>"
    echo "# To skip the Drupal Coding standard issue(s), Please use this commands << git commit -m your commit Message --no-verify >>"
    echo "-----------------------------------------------------------------------------------------------------------------------------------------${reset}"
    coding_standard_error=1
  fi
fi

# Checking for merge conflict markers.

files_changed=`git diff-index --diff-filter=ACMRT --cached --name-only HEAD --`
if [ -n "$files_changed" ]
then
  for FILE in $files_changed; do

    pattern="(<<<<|====|>>>>)+.*(\n)?"
    resulted_files=`egrep -in "$pattern" $FILE`
    if [ ! -z "$resulted_files" ]
    then
      if [ $merge_conflict -eq 0 ]
      then
        echo "${redclr}"
        echo "-----------------------Unable to commit the file(s):------------------------"
        echo "-----------------------------------${reset}"
      fi
      merge_conflict=1
      echo $FILE
    fi
  done
fi

# Printing final result

errors_found=$((synatx_error_found+debugging_function_found+merge_conflict+coding_standard_error))
if [ $errors_found -eq 0 ]
then
  echo "${greenclr}"
  echo "Wow! It is clean code"
  echo "${reset}"
else
  echo "${redclr}"
  echo "Please Correct the errors mentioned above. We are aborting your commit."
  echo "${reset}"
  exit 1
fi

Final Thoughts

I hope you found this article interesting and that it helps you write better code because better code means a better web! Liked what you just read? Consider subscribing to our weekly newsletter and get tech insights like this one delivered to your inbox!

Author: Prabhu

Meet E. Prabu, Drupal Developer, and a State Level Handball Player. Prabu remains occupied with his codes during his work hours. And when not, you’ll find him binge-playing outdoor games like Badminton. He fancies a vacation amidst the hills of Kashmir and enjoys petting the local dogs around. If you want to play handball, you know whom NOT to challenge.

Email Address Subscribe Leave this field blank Drupal Drupal Development Drupal Planet

Leave us a Comment

 

Recent Blogs

Image Image removed.

How to Adhere to Drupal Coding Standards with Git Hooks

Image Image removed.

Testing Drupal Websites for Accessibility with WCAG 2.1

Image Image removed.

Understanding Update and Post Update Hooks for Successful Drupal Site Updates

Want to extract the maximum out of Drupal? TALK TO US

Featured Case Studies

Image removed.Image removed.

Upgrading the web presence of IEEE Information Theory Society, the most trusted voice for advanced technology

Explore
Image removed.Image removed.

A Drupal powered multi-site, multi-lingual platform to enable a unified user experience at SEMI

Explore
Image removed.Image removed.

Great Southern Homes, one of the fastest growing home builders in the US, sees greater results with Drupal

Explore
View all Case Studies

Talking Drupal: Talking Drupal #400 - A chat with Dries

Today we are talking with Dries Buytaert.

For show notes visit: www.talkingDrupal.com/400

Topics
  • Favorite improvement to Drupal in last 10 years
  • Biggest opportunities and challenges facing Drupal
  • Drupalcon Portland Driesnote Ambitious site builder
  • Spoilers for the next Driesnote
  • Static site generators
  • 50,000 projects
  • Impact of AI
  • People just entering the development market
  • Last thing you coded
    • For work
    • For fun
  • Digital Public Good
Resources Guests

Dries Buytaert - dri.es

Hosts

Nic Laflin - www.nLighteneddevelopment.com @nicxvan John Picozzi - www.epam.com @johnpicozzi Stephen Cross - stephencross.com @stephencross Martin Anderson-Clutz - @mandclu

MOTW Correspondent

Martin Anderson-Clutz - @mandclu OpenAI Provides a suite of modules and an API foundation for OpenAI integration for generating text content, images, content analysis and more.

The Drop Times: A Traveler's Mindset

Each day in our life comes packed with different challenges. These challenges can sometimes be exciting and bring about a happy ending. But most of the time, challenges get coupled with difficulties. Difficulties in turn can get us stressed and even burn us out. As individuals, it is very important to convince ourselves that there seldom comes a day without a hurdle to cross. When we have such a prior understanding, challenges will fail to shock us.

I would like to put it another way. Just think about the last travel experience you had and try to remember the challenges faced. While traveling, there isn't much time available to solve a problem. We never wait for others to act first, instead we promptly go forward and find an alternative solution. A traveler is ready to seek advice from knowledgeable people without any inhibitions. Such a mindset helps to overcome any challenges on the road or anywhere. Because we know we will be stuck very badly if we do not find a solution. 

Life itself, in essence, is a journey. Nothing can help us better than to have a traveler's mindset. Now, let us journey through the important picks from the past week.

The Drop Times interviewed Margery Tongway on the sidelines of DrupalSouth. Margery Tongway is a Senior Consultant at Annex. Click here to read the interview. Read TDT's report on DrupalSouth Wellington 2023, where the Drupal community celebrated expertise and honored achievements.

A blog post published on gbyte.dev provides a detailed guide on hosting a Drupal 9 or 10 website using NixOS. In a blog titled "Disabling Twig Caching Made Simpler," Mike Herchel writes on how to disable Twig caching. Kanopi Studios has published an article explaining the benefits of a great website design. Srijan has published a new blog post on how to install Drupal 10 using Colima and DDEV on MacBook.

 An article published by StyleLib explains how Facdori theme is designed to provide a professional and modern look for industrial and manufacturing businesses. A new blog post published by Acquia discusses the capabilities and advantages of using Drupal content management system (CMS), for building e-commerce websites. A blog post published by Evolving Web explores Drupal 10 and its integration with Symfony 6.2 framework. the new PHP framework brings significant enhancements to the Drupal tech stack. 

Pantheon has introduced a new direct purchase path that allows web teams to access valuable WebOps features with ease. Follow this link to know more. See how developers can enhance the flexibility and extensibility of their Drupal-powered websites by integrating Symfony Components and Twig into Drupal Core. Selecting the right e-commerce platform can be challenging. Two popular options, Drupal Commerce and BigCommerce, stand out as top choices for businesses of all sizes. LN Webworks have published a blog post comparing both the options.

 Evolve Drupal is scheduled on 26 May 2023 in Montreal, Canada. This will be an in-person event. Click here to read more. The Drupal Bangalore User Group (D-BUG) will hold its monthly event on Saturday, 27 May, 2023. The event,  will be held at Valuebound's headquarters.

 

That is all for the week,
Your's truly,
Thomas Alias K, 
Sub-Editor, TheDropTimes

Peoples Blog: Leveraging Content Grouping for Personalized Digital Experiences

Content grouping is a powerful technique that can be leveraged to create personalized digital experiences for users. By grouping content based on specific criteria, such as user preferences, demographics, or behavior, you can deliver targeted and relevant content to individual users. Here are some ways to utilize content grouping for personalized digital experiences: User Segmentation: Segment y

LN Webworks: Drupal Single Vendor E-commerce Website: 5 Features to Consider

Image removed.

E-commerce businesses are pursuing opportunities to stand out, compete, and increase sales, regardless of their type or size. The proliferation of visitors to online marketplaces makes it challenging to distinguish oneself from the competition. That's where single-vendor e-commerce websites come in.

With a platform like Drupal Commerce, creating an empowering center for your online business has become a piece of cake. This article provides guidance on creating a memorable shopping experience using five e-commerce features, making sure they feel no regret when they choose to shop with you.

What is a Single Vendor E-commerce Website?

A single vendor e-commerce website is a platform exclusively owned and managed by a single seller, who directly offers their products or services to consumers.