Paying Attention to Drupal Admin experience

Posted on

Capturing my answer to a question on a mail list I'm on about paying attention to the Drupal admin and editor experience. Particularly, someone was asking if they should open their allowed HTML to allow pasting form and iframe tags versus the risk of being compromised by the same. My initial reply was:

If your content team is relatively small and you trust them ... I think it's OK to all form and iframe embeds.

However, if you can I'd see if you can embed these snippets via some other way, like shortcodes in WordPress or as Paragraphs in Drupal (there are probably a dozen other solutions in Drupal too) which integrate with each of those platforms. HTML is easy to break, you won't be able to just paste the HTML into your editor, and if they embed code has to change in the future (or be removed) it'll be tedious to do so.

Which lead to a longer discussion on ensuring the overall Drupal editing experience is not ignored.

First, "locking" clients out of editing templates and configuration values makes sense, if the vendor will be hosting and supporting the site long term. There's a lot going on in a CMS, and accounting for changes to configuration, CSS, templates introduced only on the production server is a migraine waiting to happen.

That said, it doesn't mean you should give up a lot of flexibility for controlling the layout of your pages and you shouldn't have to run to the vendor for every change. Things they and you should be paying attention to:

Ensuring they aren't hard coding page and node layouts in a template such that changing them later requires a lot of effort. This was a pain on a site I worked on last year and had the Webforms module enabled. Instead of using the Webforms UI to build a form and control how the fields were grouped and displayed, the previous developer did that completely via custom templates. For the client,this meant that any new form had to have a custom template for it and changes made to forms in Drupal's UI had no apparent effect (which kind of misses the point of having Drupal). Other pages on the site were handled similarly with custom templates.

Just throwing a WYWIWYG editor at your editors is also a big fail. If you have a document type which will have a link to a PDF file, don't be content with a "file explorer" type plugin for CKEditor. Have a "Related Files" field in the document content type. Editors shouldn't have to worry about how and where the file link will be rendered. Use Drupal/your CMS to consistently display the links (and integrate the PDF contents with Search, share files with other content types, etc).

For layout control within a page, Drupal has a couple of options which don't require an editor making the layout in raw HTML. I think there's a Layout builder in the latest release and there's always the "Paragraphs" module which lets you define types of blocks you can stack to build an interactive page. Conceptually not unlike Mailchimp's editor, if your familiar with it or how Gutenberg's blocks will be handled in WordPress.

Media handling in Drupal has always lagged behind WordPress. I'm not sure what the state of the art is, but the latest release has Media in core. If you're going to have a lot of photos, audio files, etc... you're better off managing them as Entities you can tag and manage like a node and not just think of them as a file you upload and link somewhere (much like images I mentioned earlier).

Also if you have some custom workflows for managing the content creation process, you should ask your vendor to use well known modules like Workbench to configure and manage the process. I wouldn't want to code a custom workflow for a client, since that becomes harder to change whereas Drupal modules exist which can let you manage and tweak those requirements in the UI (see https://www.palantir.net/blog/its-here-workbench-drupal-8

Last, I'd say make sure you have a good content model. If you are going to have blog posts, articles, and press releases --- each with their own quirks --- they should each be a content type in the admin. Don't make an uber "article" type which behaves differently depending on which fields are filled out. Within each content type, group fields which belong together, use vertical tabs or sidebars to break up forms with a lot of fields, etc... This is a good summary: https://evolvingweb.ca/blog/how-make-sure-your-content-editors-love-drupal

Tags: Drupal

─── ✧ ─── ✦ ─── ✧ ───

Creating ZIP files and streaming the response with Silex

Posted on

Creating a zip file is easy and Rob Allen has you covered on that front to get you started. I needed to do this to create a zip file of PDF files generated by Dompdf. It turns out, you can add files to a ZipArchive object without actually creating the file if you can get the contents as a string. This boils down to:

// $html is what you're going to render.
$dompdf = new DOMPDF(['defaultPaperOrientation' => 'landscape']);
$dompdf->loadHtml($html);
// this generates the PDF contents but does not output them anywhere
$dompdf->render(); 

// now we create a zip file and add the PDF
$zip = new ZipArchive();
$zip->open('/tmp/archive.zip', ZipArchive::CREATE);
// 'report.pdf' is the filename inside the zip archive
$zip->addFromString('report.pdf', $dompdf->output());
$zip->close();

The above adds one file, clearly if you want to create multiple PDFs, you would do that in a loop and call addFromString for each one. Then, if you want to stream the response to the browser with Silex (which uses Symfony components) you do:

use use Symfony\Component\HttpFoundation\ResponseHeaderBag; 

// ...

// at the end of a controller...
return $app->sendFile('/tmp/example.zip')
           ->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'your-report.zip')
           ->deleteFileAfterSend(true);

Tags: PHP, Silex, PDF, zip

─── ✧ ─── ✦ ─── ✧ ───

Everything I learned to manage my career I learned from Soccer

Posted on

This was originally posted on the mojolive blog 5 years ago, but I want to preserve it here if/when it goes down.

When I started working as a web developer, there wasn't a lot of guidance about what that meant as a career choice. Of course, back then we were getting over the excitement of the blink tag and the new design opportunities afforded by table tags. I had to figure out a career path, and I did manage to do just that by watching a lot of soccer.

1. It's not a solo effort. Rare is the player that can take the ball from one end line, dribble past 11 opponents, and score the winning goal. Even if they manage to do it during a game, they're likely to use their hand to score the next goal. It is tempting to think of your career as a solo effort, particularly in technical fields where introverts seek shelter. But the people you work alongside, meet at conventions, and connect with can be invaluable resources when you're looking for the next challenge in your career. Even at a small company, you'll have to work alongside other programmers, manager, designers, and end users. It pays off to make the effort and get to know them beyond the current project, I wouldn't be working at mojoLive if I hadn't worked with Sandy previously. Take part in your local community events and conferences too, they're great for expanding your network's reach outside of colleagues, schoolmates, and clients.

2. Serendipity complements planning When you're watching a game, and maybe dreading a scoreless tie, the entire game can change instantly. A player with a simple flick, a maze-y dribble, or an audacious goal can change the tempo and momentum of the rest of the match. It's impossible for a soccer coach to plan every movement or play, like an American football or baseball manager. It's also impossible to plan every single move in a career, no matter how good your plan is; economic conditions can change and new technologies may become popular. You have to leave room for chance and serendipity to play a part in your career, and be willing to take a risk and make a change when an opportunity presents itself.

3. Keep your skills sharp Once a player passes 30 years old, fans and coaches inevitably start asking how much longer they can play. Like any other athlete, the shelf life of a soccer player is limited by his physical condition. Some players can defy time; Preki was named Major League Soccer's MVP at the ripe old age of 40. For most of us, physical traits don't affect our job performance so drastically. But, your own shelf life is limited by the skills you acquire and use each year. If you find yourself in a rut, using the same programming language all the time, one technology stack, or targeting a single platform, make it a point to look outside your comfort zone.

4. The good players practice, practice, practice The best players have an almost single-minded focus on soccer. It might make them dull at dinner parties but it gives them an edge. They spend extra time after practice running through drills on their own, or hitting the gym on their off days. Likewise, extra-curricular projects can help you learn something new. Always building Drupal sites? Check out python and django. Have an idea that could be a useful product? Build it in your spare time, to see just what it takes to build something from start to finish.

5. Play with the best to get better I came to the game late and only started playing soccer recreationally in college. I quickly learned that playing with better players made me improve faster. Not that I ever became more than a barely adequate player, but playing with them meant I had to try to be quicker, and play smarter. Once you find a comfort zone, it's tempting to stay in it but you risk stagnation. If you find that you're a big fish in a little pond or you're a little bored with the work you're doing, its time to think about working on more ambitious projects. For programmers, a ready avenue to collaborate with other top-notch developers is through open source projects, or simply sharing code on github.

6. Don't be a one trick pony It seems every team has at least one player who is one dimensional but the coach loves for some reason. The worst is watching a player who can only shoot with his left foot. Inevitably, they'll be one-on-one with the goalkeeper, but the ball will be on their right foot. As they waste time maneuvering to get the ball on their favored left foot, a defender has time to recover and tackle the ball away. Don't be predictable. Don't stick blindly to always using the same solution whether its PHP, Drupal, or jQuery. For some projects, you'll waste time trying to fit a square peg into a round hole, when a faster, cheaper solution. It's also tempting to think of yourself as a "Back-end programmer" or a "Front-end engineer". Learning to do both not only improves your versatility, but you can speak intelligently about what it takes to do both.

─── ✧ ─── ✦ ─── ✧ ───