#! code: Drupal 10: Programatically Injecting Context Into Blocks

Context definitions in Drupal are really useful when you want to inject context into your plugins and I have been using them for a little while now. It has made building custom blocks to add content to pages much easier as I don't need to copy the same block of code to find an entity of a particular sort into the block plugin.

One problem I encountered when using this technique was when trying to programatically create and render a block. The problem was that the context wasn't available in the block when it was used in this way, and it took me a little investigation to find out how to put all of the pieces together.

Rendering a block programatically is sometimes a necessity to do when you need the block outside of the block's normal region. You might create a block that collects together the output of a number of blocks, which allows you to template them together in a very precise way. You might also need to print out a block without having to create a region on a page.

There are a few steps involved in getting things working in this way. In this article I will show how to print blocks programatically, and how to do so using context.

To show the problem in detail, let's take an example of a block called UserContextBlock that has a user entity as the available context. This is a custom block, created in a custom module.

Read more

Spinning Code: We Wish We Could Consult Like Sidney Freedman

Image removed.

Major Sidney Freedman was often the perfect psychiatrist at the perfect moment – all consultants wish we were as effective as Sidney. Major Freedman, most often referred to as Sidney, was a recurring character on M*A*S*H who comes to the 4077th a few times a season. Sidney always seems to know what his patients need; he has the perfect thing to say, while being compassionate to whoever he’s there to help (including himself).

Near Perfect Treatments

The breadth of Sidney’s skills are staggering. Sometimes simple talk therapy is all that’s needed. So when Hawkeye’s nightmares become too much Sidney pops in visit for a few sessions. And when Potter fears his surgical technique is fading a conversation with Sidney is all he needs. When everyone at M*A*S*H is stressed by their work load, a few minutes with Sidney and a prescribed bonfire steadies everyone’s nerves.

But when a really tough case comes up, Sidney is still your man. During one episode a wounded bombardier becomes convinced he’s Jesus. Sidney not only provides an emergency diagnosis but puts his career on the line to defend the man. Faced with a highly decorated soldier who is suicidal, Sidney’s quick hypnotherapy session stabilizes him. The show credits Sidney with advancing treatment of “combat fatigue” (we’ll ignore his treatment was standard 30 years before the Korean Conflict and the work of combat medics); we see him around several related patients (eventually including Hawkeye). He even remembers enough of his medical school training to pinch hit as a surgeon and offer up advice on his way out the door.

“Ladies and gentlemen, take my advice: pull down your pants and slide on the ice.”

Sindey Freedman’s best known piece of advice. Oddly fitting in the moments offered.

He even cares for himself with compassion. When patients are mad at him for his care, he knows it is part of them getting better. When he losses a patient, he knows to take a break at the 4077th and write a long letter to Sigmund Freud.

We all want to be Sidney

Everyone who works in consulting wants to be our own version if Sidney. We all want to be the person who knows exactly what’s needed at exactly the right moment. We want say all the right things. Ask the questions to get to the important truths about a project. Laugh when people are funny, then serious when we need to be. We hope to create or find the latest cutting edge solution that will provide exactly support for our client’s problem. And we want to leave them smiling and wanting more of our help.

Of course, unlike Sidney, we do not have a team of writers providing the lines. Our work doesn’t fit into tidy 22 minute episodes. New cutting edge solutions we find often don’t always work as advertised. When we are tired or frustrated, we make mistakes. When we are fresh and well rested, we still make mistakes.

The best we can do is try to follow Sidney’s example. He stays calm under stress. He stays current with his field’s research. Most importantly, he cares about his patients and provides them the best care he knows how. He even remembers to care for himself when suffering from burnout.

M*A*S*H Consulting

If you didn’t know, or can’t guess from context, my wife and I are M*A*S*H fans. We grew up with it. We bought the DVDs as they Fox released them. It’s our go-to for something comforting to watch. It’s entertaining, and full of great lines and moments to borrow for life examples. As part of marking the show’s 50th anniversary this is part of a short series of posts using consulting lessons from characters in M*A*S*H.

The post We Wish We Could Consult Like Sidney Freedman appeared first on Spinning Code.

The Drop Times: Drupal Best Integrates WebGIS with CMS: Italo Mairo

The Drop Times (TDT) approached Italo Mairo for an interview, asking questions about his work, and he was kind enough to reply via email. His answers inspire any Free Libre and Open-Source Software contributors in general and aspiring Drupal contributors in particular. It would also appeal to young engineers passionate about engineering drawing, computer graphics and visualisation. Read on to grab a bite from the exciting conversation.

Niels de Feyter: Maximize Productivity and Success as a Drupal Contractor: 6 Expert Tips

Working as a Drupal contractor can be rewarding and fulfilling, but it also comes with its own set of challenges. In this article, we'll explore 6 tips for boosting productivity and success as an independent contractor. From setting clear goals and priorities to staying organized and keeping your skills up-to-date, these tips can help you be more efficient and effective in your work. We'll also discuss the importance of networking and building relationships, as well as how to negotiate fair and reasonable rates for your services. By following these tips, you can set yourself up for success and enjoy a fulfilling career as an independent Drupal contractor.

Aten Design Group: How to Use Cypress for Testing Drupal

How to Use Cypress for Testing Drupal Image removed.jenna Fri, 01/27/2023 - 11:19 Drupal Automated Testing

If you’re not including tests in your Drupal development, chances are you think that it adds complexity and expense without providing enough benefit. Cypress is easy to learn and implement, will protect against regression as your projects become more complex and can make your development process more efficient.

Cypress is a tool for reliably testing anything that runs in a web browser. It’s open source and web platform agnostic (think: great for testing projects using front-end technologies like React) and highly extensible. It’s an increasingly popular tool and was the “#1 tool to adopt” according to Technology Radar in 2019.

In this blog, I’ll cover three topics to help you start testing in your Drupal project using Cypress:

  • Installing Cypress
  • Writing and running basic tests using Cypress
  • Customizing Cypress for Drupal

Installing Cypress

Let’s assume that you created your Drupal project using composer as recommended on Drupal.org:

$ composer create-project drupal/recommended-project cypress

Your project will have (at least) this basic structure:

vendor/   web/   .editorconfig   .gitattributes   composer.json   composer.lock

The cypress.io site has complete installation instructions for various environments; for our purposes we’ll install Cypress using npm.

Initialize your project using the command npm init. Answer a few questions that node.js asks you and you’ll have a package.json file that looks something like this:

{   "name": "cypress",   "version": "1.0.0",   "description": "Installs Cypress in a test project.",   "main": "index.js",   "scripts": {   "test": "echo \"Error: no test specified\" && exit 1"   },   "author": "",   "license": "ISC"   }

Now you’re ready to install Cypress in your project:

npm install cypress --save-dev

Let’s run Cypress for the first time:

npx cypress open

Since we haven’t added any config or scaffolding files for Cypress, it will observe It looks like this is your first time using Cypress and open the Cypress app to the welcome screen, showing both E2E Testing and Component Testing as “Not Configured”. Let’s configure your project for E2E testing: click the “Not Configured” button for E2E Testing. Cypress will report that it added some files to your project:

cypress/   node_modules/   vendor/   web/   .editorconfig   .gitattributes   composer.json   composer.lock   cypress.config.js   package-lock.json   package.json

Click on “Continue”, then choose your preferred browser for testing and click “Start E2E Testing in [your browser of choice]”.

In a separate window, Chrome will open to the Create your first spec page:

Image removed.

Click on the ‘Scaffold example specs’ button and Cypress will create a couple of folders with example specs to help you understand a bit more about how to use Cypress. Read through them in your code editor and you’ll find that the language (based in js) is intuitive and easy to follow; click on any in the Chrome test browser and you’ll see two panels: a text panel on the left, showing each step in the active spec and a simulated browser window on the right, showing the actual user experience as Cypress steps through the spec.

Open the cypress.config.js file in your project root and change it as follows:

const { defineConfig } = require("cypress");     module.exports = defineConfig({   component: {   fixturesFolder: "cypress/fixtures",   integrationFolder: "cypress/integration",   pluginsFile: "cypress/plugins/index.js",   screenshotsFolder: "cypress/screenshots",   supportFile: "cypress/support/e2e.js",   videosFolder: "cypress/videos",   viewportWidth: 1440,   viewportHeight: 900,   },   e2e: {   setupNodeEvents(on, config) {   // implement node event listeners here   },   baseUrl: "https://[your-local-dev-url]",   specPattern: "cypress/**/*.{js,jsx,ts,tsx}",   supportFile: "cypress/support/e2e.js",   fixturesFolder: "cypress/fixtures"   },   });

Change the baseUrl to your project’s url in your local dev environment.

These changes tell Cypress where to find its resources and how to find all of the specs in your project.

Writing and running basic tests using Cypress

Create a new directory called integration in your /cypress directory, and within the integration directory create a file called test.cy.js.

cypress/   ├─ e2e/   ├─ fixtures/   ├─ integration/   │ ├─ test.cy.js   ├─ support/   node_modules/   vendor/   web/   .editorconfig   .gitattributes   composer.json   composer.lock   cypress.config.js   package-lock.json   package.json

Add the following contents to your test.cy.js file:

describe('Loads the front page', () => {   it('Loads the front page', () => {   cy.visit('/')   cy.get('h1.page-title')   .should('exist')   });   });     describe('Tests logging in using an incorrect password', () => {   it('Fails authentication using incorrect login credentials', () => {   cy.visit('/user/login')   cy.get('#edit-name')   .type('Sir Lancelot of Camelot')   cy.get('#edit-pass')   .type('tacos')   cy.get('input#edit-submit')   .contains('Log in')   .click()   cy.contains('Unrecognized username or password.')   });   });

In the Cypress application when you click on test.cy.js you’ll watch each of the test descriptions on the left while Cypress performs the steps in each describe() section.

This spec demonstrates how to tell Cypress to navigate your website, access html elements by id, enter content into input elements and submit the form. (I discovered that I needed to add the assertion that the element contains the text ‘Log in’ before the input was clickable. Apparently the flex styling of the submit input was impeding Cypress’ ability to “see” the input, so it couldn’t click on it.)

Customizing Cypress for Drupal

You can write your own custom Cypress commands, too. Remember the supportFile entry in our cypress.config.js file? It points to a file that Cypress added for us which in turn imports the './commands' file(s). (Incidentally, Cypress is so clever that when importing logic or data fixtures you don’t need to specify the file extension: import './commands', not './commands.js'. Cypress looks for any of a dozen or so popular file extensions and understands how to recognize and parse each of them.)

But I digress.

Define your custom commands in this commands.js file, such as:

/**   * Logs out the user.   */   Cypress.Commands.add('drupalLogout', () => {   cy.visit('/user/logout');   })     /**   * Basic user login command. Requires valid username and password.   *   * @param {string} username   * The username with which to log in.   * @param {string} password   * The password for the user's account.   */   Cypress.Commands.add('loginAs', (username, password) => {   cy.drupalLogout();     cy.visit('/user/login');   cy.get('#edit-name')   .type(username);   cy.get('#edit-pass').type(password, {   log: false,   });   cy.get('#edit-submit').contains('Log in').click();   });

Here we’re defining a custom Cypress command called drupalLogout(), which we can use in any subsequent logic – even other custom commands. To log a user out, call cy.drupalLogout(). This is the first thing we’re doing in our custom command loginAs, in which the first thing we do is ensure that Cypress is logged out before attempting to log in as the user specified by the username and password parameters.

Using environment variables you can even define a Cypress command called drush() – using some helper functions – with which you can execute drush commands in your test writing or custom commands. How simple is this for defining a custom Cypress command that logs a user in using their uid?

/**   * Logs a user in by their uid via drush uli.   */   Cypress.Commands.add('loginUserByUid', (uid) => {   cy.drush('user-login', [], { uid, uri: Cypress.env('baseUrl') })   .its('stdout')   .then(function (url) {   cy.visit(url);   });   });

This uses the drush user-login command (drush uli for short) and takes the authenticated user to the site’s base url.

Consider the security benefit of never having to read or store user passwords in your testing. Personally I find it amazing that a front-end technology like Cypress can execute drush commands, which I have always thought of as being very much on the back end.

You’ll want to familiarize yourself with Cypress fixtures as well (fixtures are files that hold test data) - but that’s a little outside the scope of this post. Please see Aten’s webinar Cypress Testing for Drupal Websites, particularly the section on fixtures that begins at 18:33. That webinar goes into greater detail about some interesting use cases – including an ajax-enabled form - and includes a scene from Monty Python and the Holy Grail which I hope you enjoy.

Because our VP of Development, Joel Steidl, helped me define drush() as a custom Cypress command, I’d like to share that with you as well. Please feel free to use or fork Aten’s public repository on Cypress Testing for Drupal.

Happy testing!

Image removed.Jordan Graham

OpenSense Labs: Top 4 Reasons Why You Should Migrate from Drupal 7 to Drupal 10

Top 4 Reasons Why You Should Migrate from Drupal 7 to Drupal 10 Esha Banerjee Fri, 01/27/2023 - 10:24

Drupal 10 released in December 2022 and ever since, the community has been pushing its users to migrate to the latest version. 

As many as 54% of all Drupal sites are running on Drupal 7. 

Using an outdated version has downsides. Businesses miss out on technological advancements and new features that can speed up and safeguard their digital properties.

With the release of Drupal 10 and the fact that Drupal 7 will reach end of life in November 2023, it is crucial to migrate to Drupal 10 soon. Here’s why enterprises should plan their Drupal 10 migration now, and not wait until the last moment. 

Why should you migrate from Drupal 7 to Drupal 10? 

Drupal 10 brings automated updates, improved user experience, along with several other feature additions. These components will be more secure, user-friendly, and powerful. Let’s dive deep into why enterprises must plan their Drupal 7 to 10 migration. 

  1. Community support: As an open source CMS, community support is what keeps Drupal's continuous innovation ongoing. With Drupal community prioritizing and actively focusing on security of newer versions, as and when Drupal 7 reaches end of life, the community support will seize. This primarily jeopardizes the security of your Drupal 7 website. This also means that contributed modules and themes that are currently used in your Drupal 7 website, will also lose support for maintenance. This would bring challenges in website maintenance.
     
  2. New features and upgrades: Another consequence of not upgrading to latest version is that certain functionalities may cease to perform as intended. Or there may be better alternatives available. Not only can this cause extra annoyance among website maintainers, but resolving these issues may incur additional expenditures for your company owing to the time and resources required to do so. In Drupal 7, while developers had to manually upgrade/updates or search for modules from drupal.org , Drupal 10 has simplified this with Automated updates and Project browser, respectively. A lot of Drupal 7 features are either incorporated out-of-the-box in Drupal 10 or simply removed to maintain ease-of-use. 
  • Automatic updates: Drupal sites require manual upgrading, which may be challenging, time-consuming, and expensive. Delays in applying security upgrades can lead to hacked sites. The Automated Updates Initiative seeks to give Drupal sites safe, secure automatic updates. In order to minimize the total cost of ownership of maintaining a Drupal site, increase the security of Drupal sites in the wild, and lower the entry barrier for utilizing Drupal, a safe mechanism for automatically deploying updates in Drupal is to be implemented.
     
  • Project browser: Module installation and locating involve too many steps. Some steps call for you to navigate away from your Drupal site and visit Drupal.org. Other procedures, like utilizing Composer from the command line, need technical knowledge. For users who are new to Drupal and site builders, project browser aims to make it simpler to identify and install modules. This eliminates the need to visit Drupal.org or other sites. It is one of the primary Drupal strategic projects that determines the platform's development goals.
     
  • New themes: Olivero & Claro - The Drupal 7 "Seven" theme from 2009 gave off an out-of-date system impression. Seven was replaced by the new "Claro" theme, which was created in accordance with the most recent requirements. The front-end theme, "Olivero," was created to fit with features that are well-liked by users, such as the Layout Builder. The Olivero theme will be WCAG AA compliant.

The simple finding and installation of modules should empower Drupal newcomers as well as "ambitious site builders" – Dries Buytaert.

Technical Dependencies

Drupal work on current supported PHP versions. Recommended PHP versions are the best choice for building a Drupal site because they will remain supported longer. Drupal 10 is built on PHP version 8.0 while 7 isbuilt on PHP 7 which is also reaching end of life. This creates technical dependencies in supporting the platform better.

  1. jQuery, jQuery UI, jQuery Forms- Drupal 7 includes old and unsupported versions of these libraries. jQuery's current version is 3.6.x. Drupal 7 includes 1.4.2. Other libraries have comparable challenges. You may minimize this little with the jQuery Update module, although the most recent version is 2.1.x. Drupal 8 and later (as well as many other content management systems) make it simple to provide API access to your content. In the age of "publish everywhere," this is a critical feature. Drupal 7 has some basic API support, but if you want a full-fledged API with write support, you'll have to create it yourself, which adds technical debt and possible vulnerabilities.
     
  2. CKEditor 5 update from CKEditor 4 - With a thorough rebuild and an exciting new feature set, CKEditor 5 gives Drupal 10 a modern, collaborative editor experience. Users of programs like Microsoft Word or Google Docs will be used to the new CKEditor's interface. It also offers common tools for collaboration like comments, change suggestions, version histories, and other accepted editing practices. Additionally, it has outputs to.docx and.pdf files for straightforward conversion to print formats. Although the integration is still being worked on, Drupal core 9.3 already has an experimental version if you want to try it out.
     
  3. Composer 2 and PHP 8 support - Although backporting of composer 2 to Drupal 8 was successful, PHP 8 compatibility was not. PHP 8 will be required for Drupal 10 because PHP 7 will be discontinued in November 2022.

Modules that have gone out of support:

The Drupal 10 core will be updated to eliminate a few modules that are redundant or are not frequently used. For uniformity, these modules will be transferred to the Contributed Module area.

  • Gathers and presents syndicated material from outside sources (RSS, RDF, and Atom feeds).
  • QuickEdit: In-place content editing.
  • HAL - Serializes entities using the Hypertext Application Language.
  • Users may keep track of recent content with the activity tracker feature.
  • RDF – Enhances websites with metadata so that other systems may comprehend their characteristics.


You will have to leave Drupal 7 behind. Eventually, the opportunity cost of continuing to use software that is more than 10 years old is substantial, and once it is considered End of Life (EOL), the risk and expense of an uncovered vulnerability increases rapidly.

There are several possibilities available to you, and you have an additional year to choose and make plans for one of them. The ideal option will rely on the expertise level of your team, the amount of business logic you have included into Drupal 7, and your projected budget.

Conclusion 

Drupal 7 will reach end of life in November 2023, Drupal experts recommend that organizations begin migrating to Drupal 10 soon and not wait till November 2023.

If you want to migrate your website to Drupal 9 and prepare for Drupal 10, you may rely on our Drupal migration skills and expertise.

OpenSense Labs, as a Drupal partner, is committed to providing active support. Contact us at hello@opensenselabs.com for a long-term and fruitful collaboration.

Image removed.Articles Off

Promet Source: Are You Suffering from Drupal Upgrade Fatigue?

We’re hearing it these days from many of our support clients. Another upgrade?  Drupal did not always move so fast. The two and a half years between the release of Drupal 10 in December of 2022, and the release of Drupal 9 in June of 2020 is in sharp contrast to the four and a half years between the release of Drupal 8 and 9, and the nearly five years between the release of Drupal 7 and 8.

Evolving Web: A Perpetual Learner: Interview with UX/UI Designer Elena Rodriguez

Image removed.

At Evolving Web, we believe in hiring creative thinkers, and fast, practical learners. While skills like building Drupal modules and accessibility best practices can be learned in online classes, we believe there’s no substitute for grit, creativity, curiosity and self-drive. UX/UI designer Elena Rodriguez is a textbook example of an Evolving Web hire.

Image removed.Elena at the Evolving Web office in Montreal.

A Chance Encounter

A native of Barcelona, Spain, now based in Montreal, Elena is a musician – a talented pianist and choral singer – with a degree in musicology and another in philosophy. Her passion for music was what ultimately led to her emigrating to Canada.

“I first met my husband, who is Quebecois, when I was singing in a choir,” she explains. “We met in Iceland during a performance tour. We then maintained a distance relationship for three years before I eventually decided to move to Canada.”

Following her graduation, she worked in music management, mostly in archives, but felt stuck in her career, craving something that offered more in the way of continuous learning opportunities. It was through meeting people while traveling that she was introduced to web development.

Image removed.Elena playing the piano.

After taking several online courses and a bootcamp in full stack development in Barcelona, she realized that she was most interested in the visual and design aspects.

“I started to learn design basics on my own,” says Elena. “I started learning the fundamentals of design, with tools like Figma and Adobe XD. Then I learned how to actually bring these sites alive using Webflow, building small landing pages. And before long, I was doing freelance work.”

Image removed.

Learning by Doing

Elena didn’t consider herself a full-fledged designer when she applied for a job at Evolving Web. She was pleasantly surprised when we responded to her application.

 “I can’t remember how I discovered Evolving Web, but I saw a call for “spontaneous applications”. I really wasn’t expecting anybody to contact me, as my background was very broad and I knew nothing about Drupal. But I was told they were most interested in somebody who could learn quickly, and to my delight, they had a position that fit my profile.”

Elena’s first task at Evolving Web was a content entry in WordPress for a project with York University. From there, she moved onto internal design assignments in partnership with the marketing team. This has included redesign work for Evolving Web’s homepage. 

Elena says that while she had previous knowledge of UI, she needed to gain a UX background before Evolving Web, but was able to gain that knowledge and experience on the job. “The company gave me an opportunity to do a training course,” she explains. “I’ve also learned a lot from my colleagues when it comes to UX. I feel like my profile is now more UX than anything else, as most of my work is geared towards that. 

Image removed.Elena and the Evolving Web Design Team.

Embracing Company Culture

“The most challenging aspect of the job has been understanding the different roles and where everyone fits and works as a team,” she shares.

Prior to this, all of Elena’s work was as a freelancer. “I didn’t even know what a project manager did before joining Evolving Web. Understanding all the internal processes, roles and tools were challenging,” she admits. But I’ve loved the company culture from the beginning. Everyone has been wonderfully supportive and I’ve come to feel like I really fit.”

Image removed.Elena at a library in Barcelona.​​​

Evolving Elena

Elena lives in Montreal – her home for the last two years – with her husband and two cats. She says she first came to Canada as a tourist and then returned later with a work permit, spurred by a desire to live abroad.

“I really like the quality of life in Canada,” she asserts. “I feel like there are a lot more opportunities here.”

When not at work, Elena keeps herself busy practising piano and improving her French – her fourth language after Spanish, Catalan and English. She also takes Latin dance classes and is hoping to find a choir to join in her adopted hometown. Obsessed with books, she hopes to learn editorial design at some point in the future.

Image removed.Elena’s choir.

“I am obsessed with “to-learn” lists,” she says. “I want to do and learn so many new things that I need to write them down. Unfortunately, I don’t have time for all of them,” she adds reluctantly. “Professionally, I’m focusing on building expertise in the UX field and developing my visual design skills. I’m looking forward to collaborating with the great designers we have on our team. There’s so much learning and inspiration coming from them.”

Image removed.Elena loves to take on projects in her spare time, including music and creative arts.

Join Our Team

In addition to UX/UI designer Elena Rodriguez, we’ve built an eclectic team of designers, developers and marketers. Our team not only spans the globe, it also represents a wide range of academic, professional and artistic backgrounds. 

Sound like a good fit? Check out our careers page

//--> //--> //-->

 

+ more awesome articles by Evolving Web

Peoples Blog: Multisite Local environment setup with DDEV and Drupal

In this article we are going to see how we can set up a multisite environment with ddev on the local machine. Assuming people are aware of configuring the drupal multiple site from the drupal side of configurations. As we all know ddev is an open source tool for running local PHP development environments in minutes, which makes developer life easier during the local environment setup process, her