User account menu

  • Log in

Breadcrumb

  • Home
  • Drupal 8
Home
DrupalVIP
Freelancer service with great care and enthusiasm.

Main navigation

  • Home
  • Products
  • Blog
  • Support

Drupal 8

Drupal 8

Displaying 1 - 9 of 9

Drupal 7 to Drupal 9 in an hour, is it possible

Countless blog posts have been written about migrating from Drupal 7 to 8/9/10. 
Some recommend how to begin breaking down this rather overwhelming endeavor into manageable pieces. 
Others provide concrete technical recommendations for very specific Drupal 7 setups.    

DrupalVIP technical notebook & support

Drupal 9
Drupal Support
Drupal 10
Drupal Migration
Drupal 7
Drupal 8
Acquia

Custom controller with JSON response

DrupalVIP Support

how to create a custom controller with JSON response in Drupal 8.

this might work on Drupal 9 and 10, but I never tested it on these versions.

Drupal 8
JsonResponse Example
Json
Symfony
entityQuery
Code Example
HttpFoundation
Code Snippet
Node::load
routing.yml
JsonResponse
Code Snippet
use Symfony\Component\HttpFoundation\JsonResponse;

/**
 * Class JsonApiArticlesController
 * @package Drupal\mymodule\Controller
 */
class JsonApiArticlesController {

  /**
   * @return JsonResponse
   */
  public function index() {
    return new JsonResponse([ 'data' => $this->getData(), 'method' => 'GET', 'status'=> 200]);
  }

  /**
   * @return array
   */
  public function getData() {

    $result=[];
    $query = \Drupal::entityQuery('node')
      ->condition('type', 'article')
      ->sort('title', 'DESC');
    $nodes_ids = $query->execute();
    if ($nodes_ids) {
      foreach ($nodes_ids as $node_id) {
        $node = \Drupal\node\Entity\Node::load($node_id);
        $result[] = [
          "id" => $node->id(),
          "title" => $node->getTitle(),
        ];
      }
    }
    return $result;
  }
}
use Symfony\Component\HttpFoundation\JsonResponse;

// if you know the data to send when creating the response
$response = new JsonResponse(['data' => 123]);

// if you don't know the data to send or if you want to customize the encoding options
$response = new JsonResponse();
// ...
// configure any custom encoding options (if needed, it must be called before "setData()")
//$response->setEncodingOptions(JsonResponse::DEFAULT_ENCODING_OPTIONS | \JSON_PRESERVE_ZERO_FRACTION);
$response->setData(['data' => 123]);

// if the data to send is already encoded in JSON
$response = JsonResponse::fromJsonString('{ "data": 123 }');

Display Forms in a Modal Dialog

Display create a node in a modal dialog

By default when creating a node, the save action will redirect the user to another page but if we want to just close the modal dialog and leave the user on the same page we need to tell the form to do that.

For this we are going to alter the form and add an AJAX command letting Drupal know that we want to close the dialog as soon as the node is created.

Drupal 9
Ajax
Modal Dialogs
Form Attributes
JQuery
CommandInterface
AjaxResponse
Json
use-ajax
Drupal 8
Code Snippet
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\CloseModalDialogCommand;
use Drupal\Core\Ajax\RedirectCommand;

/**
 * Implements hook_form_alter().
 */
function modal_form_example_form_node_article_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $form['actions']['submit']['#submit'][] = '_modal_form_example_ajax_submit';
  $form['actions']['submit']['#attributes']['class'][] = 'use-ajax-submit';
  // in some cases this was needed:
  // $form['#attached']['library'][] = 'core/jquery.form';
  // $form['#attached']['library'][] = 'core/drupal.ajax';
}

/**
 * Close the Modal and redirect the user to the homepage.
 *
 * @param array $form
 *   The form that will be altered.
 * @param \Drupal\Core\Form\FormStateInterface $form_state
 *   FormState Object.
 */
function _modal_form_example_ajax_submit(array $form, FormStateInterface &$form_state) {
  $response = new AjaxResponse();
  $response->addCommand(new CloseModalDialogCommand());
  $form_state->setResponse($response);
}

Drupal Download & Extend: Drupal 7 End of Life

Drupal 7 will officially reach its End of Life on 5 January 2025. 

This date marks the 14th anniversary since Drupal 7 was released on 5 January 2011. 

 

It is recommended to migrate your site as soon as possible.

 

Drupal is an open-source content management platform supporting a variety of websites ranging from personal weblogs to large community-driven websites.

Drupal
Drupal 10
Drupal 7
Drupal 8
Drupal 9
Drupal Maintenance
Drupal Migration

Drush: how to Import and Export mySql database

Databases have the urge to grow, in some cases they are so big to manipulate, which means that import and export is imposible with the current tools like cPanel .

The Drush team created a tool which will help us to manipulate the database, which was defined in the settings configuration, regardless its size.

pay attention, most chance that import database will be available to files which ware created by export activity.

Drupal 8
Code Example
Drupal 7
Drupal
MySql
Drush

Field Values in Twig

Master list (in progress) of how to get parts of fields for use in Twig templates. I’m always having to look these up, so I thought I’d hash them out and write them down.

Drupal
Drupal 9
Twig
theme development
Front-End
Drupal 8
Code Example
Drupal Integration

Advance Examples Which actually needed

This article is based on the O'Reilly article which is relevant to Drupal7 and some of it for Drupal8, but drupal did a lot of modifications since then, and I believe it's a good place to start with, but still should be modified to Drupal9 and on. from time to time I will fix this article and update it according to the last drupal version, you are all invited to send me remarks and suggestions.

These examples, I believe are most needed for the more advanced Drupal backend developer.

My development strategy recommendations are:

Views
Drupal 8
Plugin
Drupal 9
Drupal 7
Code Example
Module Development
Hook
Form API
Update Mechanism

How to Send Mail from Module

Email support can be a very strong drupal capability.
You can create emails according to events, news, etc. with personalization and desired format and template.
In some cases, you need to define the email in a way that it will not appear as spam on the target email server.

Email on general drupal events like creating new articles are covered with the rules module and you don't need to program their email support.

Mail System
Send Mail
Drupal 8
Drupal 9
Code Example
Twig
theme development
Module Development
Mail Hook

Drupal 8 - Directory Structure

Whenever someone starts learning how to build sites with a new content management system, the first questions often involve how things are put together. For example, where do I put modules? Where are the theme files? What can I modify and what should I leave alone?

Drupal 8
Drupal
Module Development
Module Structure
Subscribe to Drupal 8

The Freelancer Assistance

Proactive Maintenance

Proactive Maintenance

Fullstack Service

Fullstack Service

Drupal Shared Space

Drupal Shared Space

Site Management

Site Management

Drupal Training

drupal training session

Drupal Development

Drupal Development
Review All Services

Buy Hourly Support

 

Drupal platform support for complex websites. The service includes support, training, troubleshooting, fixes, updates, tool creation and module building.
* Minimum order is for 5 hours of support
* For every 20 hours of order you will be entitled to an additional hour of support
* For every 50 hours of order you will be entitled to 5 additional hours of support

 

>> Payment <<

 
cards

מופעל על-ידי paypal

Legal

  • Home
  • Contact
  • Products

Copyright © 2026 DrupalVIP - All rights reserved

Developed & Designed by Yuval Ben-Hur