Cyber Monday Week 3: Outrunning Opponents

Today we finally came to the two most important weeks of Cyber Monday preparation plan. We already warmed up, had a workout and created targeted content, and now it’s time to run out the opponents. Days 14 – 20 of November we are going to do everything to win our competitors and attract more people to our promotional campaign. Let’s get it started!

Task 1. Give a Preview of Your Promotion

Here we should do something unexpectable. For example, discount the things we have never discounted, or announce some products we have never shown before.

Use the email you collected and promote your campaign before the Cyber Monday. Do you remember what we were talking about? When the Cyber Monday comes, everybody begins the promotional campaign. So it’s hard to predict the right time for a newsletter. If your customers are ready for shopping, you have more chances to attract most of them on Cyber Monday.

Create teaser campaign that shows your products, which will be on sale, the discounts and bonuses you are going to give on Cyber Monday. And don’t forget about the social media. Pre-Cyber Monday promotional campaign on social networks is also a good idea.Run the flash sale before the Cyber Monday. Why do you need this? – First of all, you increase the chances to sell more products, and finally, you see and reward your most loyal customers. As a result, you’ll be a step ahead of your rivals.

The goal of this task is to increase the interest to your promotional campaign, online store, and your brand in general. You have to agree that everyone likes to get presents and other pleasant things. The customers also do. They like something special. So, why not to make them happy and grow their loyalty?

Task 2. Update Your Retargeting Campaign

Add holiday-themed creative. First of all, we recommend you to update your retargeting ads and make them holiday-themed. This way you increase your chances to get more orders and turn on the positive emotions of the customers.

Adjust your budget to accommodate the increase in website holiday traffic. Yes, the traffic of your website will be much higher on holidays. And your server should be ready for this. Also, don’t forget to count the budget for shipping, packing of products and the other cost. We did it a week ago. The average growth in traffic from October to December can be up to 32%.

Imagine that you have 3000 visitors a month (current traffic).
Let’s count the possible increased traffic from November to December:

Possible Traffic = Current Traffic Current Traffic*32%
Possible Traffic: 3000 3000*32% = 3960 visitors.

You can use this formula and count your possible holiday traffic.

Incorporate social to your retargeting campaign. Social media can become your main channel of promotion. People spend much free time there and like to shop online. On average, conversion rate can increase by 73% if you use social media like an additional channel of promotion.

Now we are working on the “white paper” on Cyber Monday and preparation for any holiday in the online stores. Subscribe to our newsletter, and we promise to send it to you when it is ready. 

Task 3. Update Your Abandoned Cart Emails

Build your abandoned cart campaign. It’s very important. Do you know that reminding emails of this kind are helpful in returning the customers to the online store? They really work and grow your sales. To learn more about them, you can read our article on how to use automated emails. If you have Magento® based online store, our free Abandoned Cart extension can help you return more customers to your store.

Make your abandoned cart emails holiday-themed. This way you’ll bring the positive emotions to your customers and cheer up their mood. Also, you remind them about the necessity to place an order, because the holidays will come soon, and they should hurry up. Moreover, your offer is limited 🙂

Consider the limited time discounts and promo codes in your first Cyber Monday email. And make sure that all your coupons and unique promo codes are generated and work correctly.

Task 4. Shadow Your Opponents

This is the most interesting part of the Week-3 preparation. Now you should take on a role of Sherlock and spy in order to gather as much information about your competitors as possible. Learn more about how to explore the competitors and act like Sherlock.

Sherlock

These are the things you can do first of all:

Sign up to the opponents’ newsletter. And look what email marketing approaches they use and think about how the way you can do better.

Follow your competitors on Social Media. Look through their profiles, consider their targeted audience, and decide what you can do differently.

View your competitors’ product and landing pages, and website in general. Highlight the products that are on sale in their store, the prices they have. Then come up with your own bestsellers, discounts, and special offers.

Search your competitors in Google. See where they fall in search results, what keywords they use. Then try to overcome them. Google Keyword Planner can help you to come up with the best keywords for your campaign. Create your account there and start to optimize your website. You can also read more about this in our article on how to make keyword research.

After you do this, put all the gathered data to a sheet and create the full picture of your competitor’s portrait. Write down your ideas and use them on Cyber Monday campaign. We have already created this sheet for you, so you can copy it and use.

Click on the image below, and you’ll get the access to the sheet.

Week 3 - Outrunning the opponents

Now we have mostly everything to start our Cyber Monday campaign. It’s only one step to launching it and getting the victory. Collect all your data and plan to act on World Cyber Monday. Let’s meet in one week and complete our preparation.

Productive week to you!

P.S. Don’t forget to subscribe to our newsletter and get the Cyber Monday “white paper”  for free after its release.

Cyber Monday Week 2: Bulking Up on Content

We have already warmed up and continue to prepare for Cyber Monday. And our Week 2 will be dedicated to the creation of mega-popular targeted content.

Content and targeting go hand in hand. You can create the absolutely best message in the world, but if it’s delivered to the wrong recipients, it’ll be a real flop. The first thing we recommend to do is the segmentation of your customer database and creating the targeted content for each segment.

These are the things we are going to do this week.

Task 1. Create Segmented Holiday Email Campaigns

Segment your email database. You can make segments around demographics, purchase behavior, the number of orders, favorite products, and more other criteria for the most targeted messages.

Choose your segmentation tool and try to divide the customers into such groups as exhausted, involved, and exclusive. Then set up targeted campaigns.

Recall the last year Cyber Monday. Segment the customers who purchased from your online store last year Cyber Monday. Consider them as a loyal audience.

Create a campaign targeted to your most loyal customers and big spenders. Here you can use recency, frequency, and monetary segments. This data is often stored in your online shop database.

It’s pretty important to know what products each customer prefers. For example, if you know that your customer is a woman, and she often buys clothes in your store, it’s too little chance that she could decide to buy men’s shoes.

Task 2. Launch Your Collection of Emails

Prepare your sign-up form. Take the time to optimize your email-collecting strategy before the Cyber Monday. If it’s necessary, upgrade your sign-up form. Consider the plan on where you are going to collect emails.

Give an advantage. You can add something profitable for a customer to make him leave you the email. It could be a discount, some bonus or useful material, and other interesting things you can come up with. But this benefit should be honest and profitable.

Use these emails to premarket your Cyber Monday campaign. As far as we know, there is a large problem of Cyber Monday: you can’t predict the right time for your promotional newsletter because everybody starts to send such campaigns that day. So, it’s better to prepare your customers for shopping and give them a reason to visit your online store on Cyber Monday before it starts.

Now we are working on the “white paper” on Cyber Monday and preparation for any holiday in the online stores. Subscribe to our newsletter, and we promise to send it to you when it is ready. 

Task 3. Add Shopping Opportunities on Social Mediasocial media shopping

 

Increase the frequency of your social media posting. Start your promotional campaign on social networks and announce your products and discounts more often. This way you attract the larger audience.

Build your social media content ahead of time. We should be ready for daily and weekly posting on social media. And it’s great to have a step-by-step plan. Do you remember? We did it last week and created a calendar with a plan. And we should have all the things done and prepared, and just post the content on the planned dates.

Canva is a good helper in creating graphical content for social networks. It offers a large number of opportunities for work with images and allows you to create the posts exactly according to the social network format.

Add custom landing pages to your social media profile. And start to promote them. A landing page is a good way to encourage sales. It gathers your customers in one place and helps them to shop online or get their benefits quickly and easy.

A holiday-themed custom design attracts the visitors and turns on their emotions. So we recommend you to pay special attention to the design and UX of your holiday landing pages.

We want to help you create your content plan. Click on the image below, and you’ll get the access to the file. You can copy it and use.

content plan

Make your website and content mobile-friendly. Nearly 80% of social media time is spent on mobile devices. If you know what I mean:) If your website works right on mobile devices, and social media campaigns are also comfortable there, you get more chances to get more orders.

Check your website for mobile-friendliness with Google SpeedInsights, and focus on such things as the color and size of fonts, the color of backgrounds, the size of call-to-action buttons and other important details of your web pages. Test your campaigns before launch.

Prepare for Cyber Monday Week 1: Warm-Up

We continue to prepare for Cyber Monday, and our first week starts with the warm-up. We have already know that Cyber Monday is a real competition, and we should be ready for this. If you missed our previous article, you can look at our plan for Cyber Monday.

Cyber Monday will be in 3 weeks. So we should go a bit quicker, and do all the following assignments for several days:

Task 1. Set Up Your Holiday Analytics

Set up your analytics right. In this case, Google Analytics will be a useful tool for you. We mean that you should set your goals in Google Analytics correctly, decide what parameters are the most important for you to track. They could be the number of orders, website visitors, the sources of traffic, demographic, and others. Here you can find the ultimate Google’s guide on how to set goals.

Take the previous year statistics. It is very important because you have some data for analysis from the last year and can make up your mind on what thing worked and what actions need improvement. Also, it’s necessary to have some starting point, in order to evaluate the future results and track the efficiency.Consider multi-channel tracking and analytics. As far as we know, we should use all the channels we can in order to broaden our audience. That’s why tracking traffic and conversion from social networks, email marketing campaigns, advertisements, and landing pages via Google Analytics is a great idea.

Task 2. Evaluate Your Inventory

Check your inventory stock. It is necessary in order to be sure you can accommodate to increase in sales. The inventory includes costs for shipping, packing of products, staff salary, website support, etc.

Prioritize the product promotion. We should decide where we’ll promote our products, and what channels and products should be at the top of our promotional campaign.

Now we are working on the “white paper” on Cyber Monday and preparation for any holiday in the online stores. Subscribe to our newsletter, and we promise to send it to you when it is ready. 

Task 3. Prepare Your Website

Don’t hide the main categories. When we talk about holidays on the website, we should show the holiday categories first of all.

Optimize your website for mobile. Now 80% users come to the websites via mobile devices and want to shop online from any part of the world. Don’t lose such a large audience. If you want to know whether your website is mobile friendly, you can check it with Google test, using Google SpeedInsights. It will show the points you have for the mobile version. If the row of points is red, you need to improve something.

Task 4. Create Promotional Calendar

Map your promotional points. Create your plan of promotion: what campaigns, actions, and posts you will launch and what day. Then create a table and fill it with your plan. You can also use the calendar (for example, Google calendar or iCalendar), which is the most comfortable for you, and map there your points. This way you’ll forget nothing.

We prepared the sheet for you, where you can do all the action considered above. Click on the image below and get the access to it. You can copy this sheet and fill it with your values.

promotional table

Maintain the database of coupon codes. We should be sure that all of them are in the right place. So try to predict any scenario and test each of them.

Prepare for Cyber Monday: The Ultimate Guide

November has already started its walk, and that means only in 1 month we’ll have Cyber Monday. It is a great opportunity for the business owners to promote their brand and increase their sales drastically.

What is Cyber Monday?

Cyber Monday comes after Black Friday as a great opportunity for the online stores. It’s a perfect day for growing your sales online because people still continue to buy products at the online shops via their office computers.

This guide is based on the case study and results of the experts who gave the report on a webinar organized by Magento®.

What We Plan to Do?

We are going to follow a 4-week plan of preparation for Cyber Monday on November 27th. You’ll get the cycle of articles, which will help you to prepare for any kind of holiday and event. Each of these articles will describe one step of our plan. Like before the sports competition, we’ll do several activities:

1. Warm-up. As a result of warm-up, you will be able to:

  • see the moments that need improvement;
  • count the supposed revenue from the successful campaign;
  • estimate the necessary resources and needed budget.

2.  Bulking up on content. As a result, you will be able to:

  • organize a customers base and segment them for targeted campaign;
  • create the targeted content for each channel and an audience group;
  • develop the successful themed design for each campaign.

3.  Outrunning the opponent. As a result, you’ll be able to:

  • know what advantages and disadvantages has your opponent;
  • plan your efficient promotional campaign before the Cyber Monday;
  • prepare a customer for shopping in your online store on Cyber Monday.

4.  Final stretch. As a result, you’ll be able to:

  • finally, prepare your online store for Cyber Monday;
  • plan all promotional campaigns for Cyber Monday;
  • test everything and be sure that your campaigns work right.

then we’ll meet Cyber Monday and our victory on November 27th.

A bonus for winter holidays: you’ll learn how to get all benefits before and after the winter holidays in December and January and summarize the results.

Why is Cyber Monday So Important?

As the statistic says, if the campaign is successful, we can get the following results between November 1st and December 31st:

  • up to 6% of holiday revenue in December;
  • up to 70% increase in sales from November 20th to November 27th.

And you should also know that 40% of shoppers start their holiday shopping by Halloween. Following the statistics, we can create the calculation formula of supposed revenue.

Let’s imagine that:

  • we have 5000 visitors on your website a week;
  • our conversion rate is 5%;
  • our average check is 100$ a week.

Let’s calculate our supposed revenue (SRev) from the week before Cyber Monday.

SRev = average weekly revenue 70% growth in week before Cyber Monday revenue

Average weekly revenue: 5000 * 5% *100$ = 25000$
70% growth in week before Cyber Monday revenue: 25000$ * 70% = 17500$
SRev: 25000$ 17500$ = 42500$

So, you can put your values to this formula and calculate your supposed revenue. If you prepare for the Cyber Monday correctly, you’ll get the high revenue.

And we’ll help you to be ready.

By the way, now we are working on the “white paper” on Cyber Monday and preparation for any holiday in the online stores. Subscribe to our newsletter, and we promise to send it to you when it is ready. 

The Problems of Cyber Monday

Firstly, we should focus on the things that work and things that don’t work. The main task is to be aware of the common problems and find the solution for them.

Here are the main problems of Cyber Monday:

  • Slow and crashing websites. When the number of your online store visitors increases in many times, the servers could be overloaded.

That’s why we should check the peak website load and page loading speed. In general, good speed is 1-2 seconds per page, not more. And page loading speed affects the conversion. So, pay a special attention to these moments and improve them if you need. The following tools can help you to test your website and know the page loading speed: PingdomWebsite Grader, Google PageSpeed insights.

  • Not having channel-by-channel and overall measuring marketing plan. If we want to get results and take control of everything, the goals should be measurable and result fixed. We should create a step-by-step plan for our going to the victory.

Decide what channels you will use for promotion (social networks, email marketing, advertising, landing pages) and set up the goals in Google Analytics.

  • Not planned budget. If we are going to create a marketing campaign, we should know how many resources we need and the main steps.

Estimate the necessary number of resources you can spend on each channel.

  • Unprofitable discounts. It really happens. When everybody offers discounts, they lose their value.

So we need to come up with something new in order to stand out from the crowd.

  • Timing. Again, when everybody starts to send promotional email newsletters on Monday, you can’t predict the best time for the successful email campaign.

Launch your marketing campaigns a week before Cyber Monday and offer profitable discounts and coupons, which people we’ll be able to use on Cyber Monday shopping. Start to prepare your customers.

So, we offer you the following. First of all, consider these problems and try to find the solutions for them. Create a sheet and fill it with ideas.

Click on the image below, and you’ll get the access to the sheet we prepared for you. You can copy it and fill with your data.Cyber Monday Problems
Stay with us, and the next time we’ll do the warm-up. Hurry up – it’s 3 weeks between Now and Cyber Monday. The time is on.

Ready, steady, go!

P.S. Don’t forget to subscribe to our newsletter and get the Cyber Monday “white paper”  for free after its release.

Case study: Migrating to Magento 2 for E-Store

Everybody knows that Magento® released a new version, which has already become the wished platform for the website owners who like to follow trends and keep pace with time.

WEB4PRO team completed the project based on Magento 2. So we did something we can be proud of.

We had a task to perform migration to Magento 2 for the jewelry online store based on Magento. The most works were done on the back-end. And it took us nearly a month to complete the task.

Migration to Magento 2: How It Was

First of all, we migrated all online store data to Magento 2. Also, there were several custom modules that needed to be moved to Magento 2. So we converted them, and it allowed the store owner to get all his custom solution safely.

The next thing we did was the extending of Ajax adding to cart. The solution was in creating the block which shows the product added to the cart after the user adds it.

Also, we customize the search on the store and adapted the layout to the design.

State API and Configuration API in Drupal 8

Very often we need to write some data into the variable, which we can replace at any moment of use. There are two such functions in Drupal 7: variable_get() and variable_set(). In Drupal 8 we have State API and Configuration API for these purposes. In this article, you’ll familiarize with their use and also tell the difference between them.

State API

State API should be used bypassing configuration only when your goals of use meet the following requirements:

  • This API will be used for storage of some system information;
  • You are not going to transfer the setup data from server to server because the data won’t be saved in case of exporting configuration;
  • These data won’t be edited by the user through the interface.

A good example of State API use is storing the timestamp of the last cron operation run.

State API: Writing Values

For entry, we should use a pair: a key and a value.

Drupal::state()->set('key','value');

For multiple entries we use the following code:

// $values - array with the couple of key and value. 
$values = [
'key1' => 'value1',
'key2' => 'value2'
];
Drupal::state()->setMultiple($values);

State API: Getting Data

Getting one value with a key.

$val = Drupal::state()->get('key');

Getting several values:

$keys = [
'key',
'key2'
];
$pairs = Drupal::state()->getMultiple($keys).// $values - array with the couple of key and value. 
$values = [
'key1' => 'value1',
'key2' => 'value2'
];
Drupal::state()->setMultiple($values);

State API: Deleting Data

Deletig is accessible only with one value:

Drupal::state()->delete('key');

When you use Configuration API, setup data will be saved. If you export the website configuration, you’ll find name.settings.yml file with the following content key value.

Configuration API

Configuration API: Creating the Configuration Object

$config = Drupal::config(‘name.settings');
Configuration API: Writting values.
$config->set('key','value');
$config->save();
Configuration API: ????????? ??????.
$config->get('key'); // value.
Configuration API: Deleting data.
$config->delete('key');
$config->save();

Now if you export the website configuration, you’ll find name.settings.yml file with the following content key value.

Hope that this quick tip was useful for you! if you don’t want to spend your time on all these works, just let us know and we’ll do all necessary works on Drupal development for you. Leave your contacts in “Ask Questions” form below, and we’ll get acquainted for an interesting discussion. Wish you good luck and friendship with Drupal.

We Launched a Blog on Web and Business!

High five! We did it! It is an important day in WEB4PRO history.

We had been working on it for one year, and finally, we launched our new blog!

Our Blog is a Place for Your Development

And we are happy to invite everybody for staying here and reading our new articles on web tools, business, marketing, and self-development. We are going to share our news with you here, represent our new products, and provide you only with the most useful things from the Internet world and business development.

Our team aims to make you interested and become your best helper in growing your business success. Here you’ll find the best practices on Drupal, Magento®, and WordPress development, get acquainted with the latest web design trends, learn more about modern technologies, and interesting approaches to running the business and marketing strategy.

Come round and stay with us forever! We promise you’ll not be bored 🙂

Welcome to WEB4PRO blog!

Drush and Drupal Console: Test-Drive

Drush and Drupal Console are the utilities with a command line interface. Both of them drastically speed up website administration and development. After the installation, you’ll have an ability to take the specific actions just entering the command into the terminal window, while the same actions could require several steps in a browser, for example.

Drupal Console works only with Drupal 8, and Drush works with Drupal 6, 7, 8.
We think you should know both of these tools if you will work with Drupal 8.

Comparing Drush and Drupal Console

What can we do using these tools? – Look through the list below.

With Drush you can:

  • Download and install Drupal and contributed modules;
  • Update Drupal and contributed modules;
  • Run updates;
  • Clean cash;
  • Run CRON and Drupal on a light web server;
  • Import, export, and merge configurations;
  • Add users and set up the roles for them and access permission for roles;
  • Make Drupal backup and recovery;
  • Copy database and files to the remote server;
  • Make a copy of twig templates.

With Drupal Console you can:

  • Generate code for:
    — Console commands;
    — Content types;
    — Controllers;
    — Entities;
    — Form alter hooks;
    — Fields types, field widgets, and output widgets.;
    — Images effects;
    — Rest resources;
    — Services;
    — Themes;
  • Switch the website to the maintenance mode and back;
    Run unit tests.

Hope that you are interested and ready to start working. We think that Linux and Mac OS users don’t need telling about terms. But as for Windows users, we’ll recommend them to use Git Bush instead of a standard console. You can download Git for Windows here.This article will be useful for those who has the skills of working with the console. So let’s open our console!

Working with Drush and Drupal Console

Drush and Drupal Console are very similar, but they are two different packages. Therefore they should be installed separately:

  • Here is a guideline on Drush installation.
  • And here is a guideline on Drupal Console installation.

After the installation of packages, make sure that you did everything correctly. Enter Drush version and Drupal version in a console for this. Then you’ll see something like the information showed below. The numbers of versions could be different in your system.

<div class="half-left">
  <p><strong>Drush</strong></p>
  <p>$ drush version<br>Drush Version : 8.0-dev</p>
</div>

Drupal Console

$ drupal --version
Drupal Console version 0.9.1

Now let’s show the power of Drush in Drupal Console using them together. First of all, we’ll use Drush for Drupal 8 download, installation, and run via pm-download (dl) and quick-drupal (qd) commands.

$ drush dl drupal-8.0.x
Project drupal (8.0.x-dev) downloaded to /Users/ga/tmp/intro-drush/drupal-8.0.x-dev.
Project drupal contains:
- 1 profile: standard
- 13 themes: 
- 62 modules: 
$ cd drupal-8.0.x
$ drush qd --use-existing --uri=http://localhost:8383 --profile=standard
You are about to DROP all tables in your ‘…/drupal-8.0.x-dev.sqlite’ database. Do you want to continue? (y/n): y
Starting Drupal installation. This takes a while. Consider using the --notify global option.
Installation complete.  User name: admin  User password: 
Congratulations, you installed Drupal!
Caching 'uri' localhost:8383 in /drush/drushrc.php
HTTP server listening on localhost, port 8383 (see http://localhost:8383/), serving site localhost:8383, logged in as admin...
PHP 5.6.12 Development Server started at Thu Sep 24 15:02:53 2015
Listening on http://localhost:8383
Document root is /drupal-8.0.x-dev
Press Ctrl-C to quit.

After you have seen the message in the terminal shown above, it should be a little pause, and the browser will open the just installed Drupal website in few seconds. Quickly and simply!

Then we’ll use Drupal Console for creating the module for Drupal 8. Type the commands shown below in the terminal.

$ drupal generate:module
Welcome to the Drupal module generator
Enter the new module name: hello
Enter the module machine name [hello]: hello
Enter the module Path [/modules/custom]: /modules/custom
Enter module description [My Awesome Module]: Hello World
Enter package name [Other]: Other
Enter Drupal Core version [8.x]: 8.x
Do you want to add a composer.json file to your module [no]? yes
Would you like to add module dependencies [no]? no
Do you confirm generation [yes]? yes
Generated or updated files
Site path: /drupal-8.0.x-dev
1 - modules/custom/bello/bello.info.yml
2 - modules/custom/bello/bello.module

Perhaps, you thought that you knew how to develop modules for Drupal 8, didn’t you? In any case, you have just created module via Drupal Console using only one single command. It’s cool, but the module lacks its own controller. And the module without the controller in Drupal 8 is just like a module without hook_menu() for Drupal 7. So, let’s go on and make our module do something. We are going to use the features of Drupal Console again:

$ drupal generate:controller
Welcome to the Drupal Controller generator
Enter the module name: hello
Enter the Controller class name [DefaultController]: HelloController
Controller title: Hello World
Enter the action method name [index]: greet
Enter the route path [hello/greet/{param_1}/{param_2}]: hello/greet/{world}
Controller title (empty to start with code generation):
Do you want to generate a unit test class [yes]? yes
Do you want to load services from the container [no]? no
Do you confirm generation [yes]? yes
Generated or updated files
Site path: /drupal-8.0.x-dev
1 - modules/custom/hello/src/Controller/HelloController.php
2 - modules/custom/hello/hello.routing.yml
3 - modules/custom/hello/Tests/Controller/HelloControllerTest.php
[ ] Rebuilding routes, wait a moment please
[ ] Done rebuilding route(s).

Controller generation successfully completed. Let’s look what it generated for us:

$ tree modules/custom/
modules/custom/
??? hello
   ??? Tests
   ?   ??? Controller
   ?   	??? HelloControllerTest.php
   ??? composer.json
   ??? hello.info.yml
   ??? hello.module
   ??? hello.routing.yml
   ??? src
       ??? Controller
           ??? HelloController.php

Open HelloController.php file in your favorite editor and replace the things transmitted to a function t() with the data shown in the example below.

class HelloController extends ControllerBase {
 /**
  * Greet.
  *
  * @return string
  *   Return Hello string.
  */
 public function greet($world) {
   return [
       '#type' => 'markup',
       '#markup' => $this->t('Hello, @world!', array('@world' => $world))
   ];
 }
}

Now it looks like the right Hello World module. Let’s turn it on using Drush.

$ drush en hello
The following extensions will be enabled: hello
Do you really want to continue? (y/n): y
hello was enabled successfully.

As you can see, it’s pretty simple to manage Drupal and generate code using Drush and Drupal Console. And these powerful tools can become your best friends while working on Drupal 8. If you need any help on Drupal development, we’ll do these works for you with great pleasure. Just fill “Ask Questions” form below, and we’ll contact you.

Arg Function: How to Replace It in Drupal 8

Arg function was excluded from Drupal 8. But you can replace it simply.

We have url /node/1

Arg Function in Drupal 7

On Drupal 7 we used it in such way:

echo arg(0); // node
echo arg(1); // 1

Arg Function in Drupal 8

In Drupal 8 we use OOP replacement of this function:

$route_match = Drupal::routeMatch()->getParameter('node');

Drupal::routeMatch()->getParameter('node')

Returns the processed value of the “node” route.

As the result, we have an object, from which we can get not only node id but also fields of a node. For example:

$node_id = $route_match->id(); // We’ve got node id (1)
$node_bundle = $route_match->bundle(); // We’ve got bundle nodes (article).

You may find the following example of function replacement in Drupal 8 on the Internet:

$path_args = explode('/', current_path());
echo $path_args[0]; // node
echo $path_args[1]; // 1

In such case of use, we can catch an error with empty or not existing elements.

That’s why, it’s better to use OOP variant of function replacement, which is suggested by the official drupal.org resource. That’s all. Simply and quickly 🙂 But if you have any difficulties, please, contact us and we’ll save your time and do everything related to Drupal development and customization for you.

Form_state in Drupal 7 and Drupal 8

Drupal 7 uses hook form(), form validate(), form submit() hooks for creation, validation, and submission of the form. $form_state array is used for getting values of the filled fields. And today we are going to tell the difference between form_state in Drupal 7 and Drupal 8.

Here is how it works in Drupal 7:

// Get the field value 
echo $form_state['values']['field_id'];
// Get all values of the form
$values = $form_state['values'];

As Drupal 8 is completely based on OOP, the form is an entity here. So, forms are classes (OOP), which are created, implementing an interface:
DrupalCoreFormFormBuilderInterface.

There are several abstract form classes for different tasks in Drupal 8 core, which you should base on while subclassing:

All data, which the user entered while filling the form, will be in a $form_state variable. But $form_state is an entity in Drupal 8, so you should use the following code to get the necessary field value:

// field_id - name of the form element (a key).
echo $form_state->getValue('field_id');
Use the following method for getting all values:
// Get all form values
$values = $form_state->getValues();

That’s the way it works. We hope it’s helpful for you, but nevertheless, if you need any help, contact us, and we’ll do all necessary work on Drupal development for you.