Matt Glaman-Drupal 8 Development Cookbook-Packt Publishing (2016) 1.Pdf

Total Page:16

File Type:pdf, Size:1020Kb

Matt Glaman-Drupal 8 Development Cookbook-Packt Publishing (2016) 1.Pdf Drupal 8 Development Cookbook Over 60 hands-on recipes that get you acquainted with Drupal 8's features and help you harness its power Matt Glaman BIRMINGHAM - MUMBAI Drupal 8 Development Cookbook Copyright © 2016 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: March 2016 Production reference: 1040316 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78588-147-3 www.packtpub.com Credits Author Project Coordinator Matt Glaman Shweta H Birwatkar Reviewer Proofreader Todd Zebert Commissioning Editor Indexer Amarabha Banerjee Tejal Daruwale Soni Acquisition Editor Graphics Manish Nainani Jason Monteiro Content Development Editor Production Coordinator Deepti Thore Manu Joseph Technical Editor Cover Work Naveenkumar Jain Manu Joseph Copy Editors Ting Baker Rashmi Sawant About the Author Matt Glaman is a developer at Commerce Guys. He is an open source developer who has been working with Drupal since 2013. He has also been developing web apps for many years prior to this. Since then, he has contributed to over 60 community projects, including being a co-maintainer of Drupal Commerce. While mostly focusing on Drupal and PHP development, he created https://contribkanban.com, an AngularJS application, to provide Kanban boards for the Drupal community to collaborate with. I would like to thank, and I am grateful to, my beautiful and loving wife for putting up with the late nights split between work, spending time contributing to the Drupal community, and writing this book. I would also like to thank my two sons; thank you for giving up your playtime so that Daddy could write this book. and kicking off my Drupal career. I would also like to thank my mentors Drupal community! About the Reviewer Todd Zebert has been involved with Drupal since version 6. He is a full-stack web developer Miles. He has also been a technical reviewer for Developing with Drush, Packt Publishing. He has a diverse background in technology, including infrastructure, network engineering, project management, and IT leadership. His experience with web development started with the original Mosaic graphical web browser, SHTML/CGI, and Perl. He's an entrepreneur involved with the Los Angeles start-up community. He's a believer in volunteering, open source, the Maker movement, and contributing back. He's also an advocate for Science, Technology, Engineering, Art, and Math (STEAM) education. I'd like to thank the Drupal community, which is like no other. Finally, I'd like to thank my pre-teen son with whom I get to share my interest in technology and program video games and microcontrollers. www.PacktPub.com eBooks, discount offers, and more Did you know that Packt offers eBook versions of every book published, with PDF and ePub www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM https://www2.packtpub.com/books/subscription/packtlib library. Here, you can search, access, and read Packt's entire library of books. Why Subscribe? Fully searchable across every book published by Packt Copy and paste, print, and bookmark content On demand and accessible via a web browser Table of Contents Preface v Chapter 1: Up and Running with Drupal 8 1 Introduction 1 Installing Drupal 2 Using a distribution 8 Installing modules and themes 10 Using multisites in Drupal 8 14 Tools for setting up an environment 16 Running Simpletest and PHPUnit 18 Chapter 2: The Content Authoring Experience 23 Introduction 23 Adding and editing content 27 Creating a menu and linking content 30 Providing inline editing 32 Creating a custom content type 34 Customizing the form display of a node 40 Customizing the display output of a node 43 Chapter 3: Displaying Content through Views 47 Introduction 47 Listing content 48 Editing the default admin interfaces 52 Creating a block from a View 55 Utilizing dynamic arguments 58 Adding a relationship in a View 61 Providing an Entity Reference result View 66 i Table of Contents Chapter 4: Extending Drupal 69 Introduction 69 Creating a module 70 Using Features 2.x 90 Chapter 5: Frontend for the Win 97 Introduction 97 Creating a custom theme based on Classy 98 Using the new asset management system 102 Twig templating 109 Using the Breakpoint module 113 Using the Responsive Image module 115 Chapter 6: Creating Forms with the Form API 121 Introduction 121 Creating a form 122 Using new HTML5 elements 128 Validating form data 132 Processing submitted form data 136 Altering other forms 140 Chapter 7: Plug and Play with Plugins 145 Introduction 145 Creating blocks using plugins 146 Creating a custom plugin type 169 Chapter 8: Multilingual and Internationalization 181 Introduction 181 Translating administrative interfaces 182 Translating content 191 Creating multilingual views 195 Chapter 9: Introduction 201 ii Table of Contents Chapter 10: The Entity API 225 Introduction 225 Creating a content entity type 237 Creating a bundle for a content entity type 247 Implementing custom access control for an entity 257 Providing a custom storage handler 264 Creating a route provider 267 Chapter 11: Off the Drupalicon Island 273 Introduction 273 Implementing and using a third-party JavaScript library 274 Implementing and using a third-party CSS library 279 Implementing and using a third-party PHP library 284 Using Composer manager 287 Chapter 12: Web Services 293 Introduction 293 Enabling RESTful interfaces 294 Using GET to retrieve data 299 Using POST to create data 302 Using PATCH to update data 307 Using Views to provide custom data sources 310 Authentication 313 Chapter 13: The Drupal CLI 319 Introduction 319 Rebuilding cache in Console or Drush 320 Using Drush to interact with the database 321 Using Drush to manage users 325 Scaffolding code through Console 327 Making a Drush command 330 Making a Console command 335 Index 341 iii Preface Drupal is a content management system used to build websites for small businesses, e-commerce, enterprise systems, and many more. Created by over 4,500 contributors, Drupal 8 provides many new features for Drupal. Whether you are new to Drupal, or an experienced Drupalist, Drupal 8 Development Cookbook contains recipes that help you immerse yourself in what Drupal 8 has to offer. What this book covers Chapter 1, Up and Running with Drupal 8, covers the requirements to run Drupal 8, walks you through the installation process, and extends Drupal. Chapter 2, The Content Authoring Experience, dives into the content management experience in Drupal, including working with the newly bundled CKEditor. Chapter 3, Displaying Content through Views, explores how to use Views to create different ways to list and display your content in Drupal. Chapter 4, Extending Drupal, explains how to work with Drupal's Form API to create custom forms to collect data. Chapter 5, Frontend for the Win, teaches you how to create a theme, work with the new templating system, Twig, and harness Drupal's responsive design features. Chapter 6, Creating Forms with the Form API, teaches you how to write a module for Drupal, the building blocks of functionalities in Drupal. Chapter 7, Plug and Play with Plugins, introduces plugins, one of the newest components in Chapter 8, Multilingual and Internationalization, introduces features provided by Drupal 8 administration. v Preface Chapter 9, Chapter 10, The Entity API, dives into the Entity API in Drupal, allowing you to create custom Chapter 11, Off the Drupalicon Island, explains how Drupal allows you to embrace the mantra of proudly built elsewhere and includes third-party libraries in your Drupal site. Chapter 12, Web Services, shows you how to turn your Drupal 8 site into a web services API provider through a RESTful interface. Chapter 13, The Drupal CLI, explores working with Drupal 8 through two command-line tools created by the Drupal community: Drush and Drupal Console. What you need for this book In order to work with Drupal 8 and to run the code examples found in this book, the following software will be required: Web server software stack: Web server: Apache (recommended), Nginx, or Microsoft IIS Database: MySQL 5.5 or MariaDB 5.5.20 or higher PHP: PHP 5.5.9 or higher Chapter 1, Up and Running with Drupal 8, details all of these requirements and includes a recipe that highlights an out of the box development server setup. Atom.io editor: https://atom.io/ https://www.jetbrains.com/ phpstorm/ https://www.drupal.org/project/vimrc Who this book is for This book is for those who have been working with Drupal, such as site builders and backend and frontend developers, and who are eager to see what awaits them when they start using Drupal 8.
Recommended publications
  • Download the Specification
    Internationalizing and Localizing Applications in Oracle Solaris Part No: E61053 November 2020 Internationalizing and Localizing Applications in Oracle Solaris Part No: E61053 Copyright © 2014, 2020, Oracle and/or its affiliates. License Restrictions Warranty/Consequential Damages Disclaimer This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. Warranty Disclaimer The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. Restricted Rights Notice If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, then the following notice is applicable: U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs) and Oracle computer documentation or other Oracle data delivered to or accessed by U.S. Government end users are "commercial
    [Show full text]
  • Potranslator Documentation Release 1.1.5
    potranslator Documentation Release 1.1.5 SekouD Nov 01, 2018 Contents 1 potranslator 3 1.1 Supported Languages..........................................3 1.2 Quick Start for auto-translation with potranslator............................6 1.3 Basic Features..............................................7 1.4 Optional features.............................................7 1.5 Installation................................................8 1.6 Commands, options, environment variables...............................8 1.7 License..................................................9 1.8 Original..................................................9 1.9 CHANGES................................................9 2 Installation 11 2.1 Stable release............................................... 11 2.2 From sources............................................... 11 3 Usage 13 3.1 From a Python program......................................... 13 3.2 Commands, options, environment variables............................... 13 4 Package Api Documentation for potranslator 17 4.1 API Reference for the classes in potranslator.potranslator.py...................... 17 5 Contributing 19 5.1 Types of Contributions.......................................... 19 5.2 Get Started!................................................ 20 5.3 Pull Request Guidelines......................................... 21 5.4 Tips.................................................... 21 5.5 Deploying................................................ 21 6 Credits 23 6.1 Development Lead...........................................
    [Show full text]
  • Open Source License and Copyright Information for Gplv3 and Lgplv3
    Open Source License and Copyright Information for GPLv3/LGPLv3 Dell EMC PowerStore Open Source License and Copyright Information for GPLv3/LGPLv3 June 2021 Rev A02 Revisions Revisions Date Description May 2020 Initial release December 2020 Version updates for some licenses, and addition and deletion of other components June, 2021 Version updates for some licenses, and addition and deletion of other components The information in this publication is provided “as is.” Dell Inc. makes no representations or warranties of any kind with respect to the information in this publication, and specifically disclaims implied warranties of merchantability or fitness for a particular purpose. Use, copying, and distribution of any software described in this publication requires an applicable software license. Copyright © 2020-2021 Dell Inc. or its subsidiaries. All Rights Reserved. Dell Technologies, Dell, EMC, Dell EMC and other trademarks are trademarks of Dell Inc. or its subsidiaries. Other trademarks may be trademarks of their respective owners. [6/1/2021] [Open Source License and Copyright Information for GPLv3/LGPLv3] [Rev A02] 2 Dell EMC PowerStore: Open Source License and Copyright Information for GPLv3/LGPLv3 Table of contents Table of contents Revisions............................................................................................................................................................................. 2 Table of contents ...............................................................................................................................................................
    [Show full text]
  • Jinja Documentation (3.0.X) Release 3.0.0
    Jinja Documentation (3.0.x) Release 3.0.0 Pallets May 11, 2021 CONTENTS: 1 Introduction 3 1.1 Prerequisites...............................................3 1.2 Installation................................................3 1.3 Basic API Usage.............................................4 2 API 5 2.1 Basics...................................................5 2.2 Unicode..................................................6 2.3 High Level API..............................................6 2.4 Autoescaping............................................... 13 2.5 Notes on Identifiers............................................ 14 2.6 Undefined Types............................................. 14 2.7 The Context............................................... 17 2.8 Loaders.................................................. 18 2.9 Bytecode Cache............................................. 21 2.10 Async Support.............................................. 23 2.11 Policies.................................................. 23 2.12 Utilities.................................................. 24 2.13 Exceptions................................................ 25 2.14 Custom Filters.............................................. 26 2.15 Evaluation Context............................................ 27 2.16 Custom Tests............................................... 28 2.17 The Global Namespace.......................................... 28 2.18 Low Level API.............................................. 29 2.19 The Meta API.............................................
    [Show full text]
  • Translate's Localization Guide
    Translate’s Localization Guide Release 0.9.0 Translate Jun 26, 2020 Contents 1 Localisation Guide 1 2 Glossary 191 3 Language Information 195 i ii CHAPTER 1 Localisation Guide The general aim of this document is not to replace other well written works but to draw them together. So for instance the section on projects contains information that should help you get started and point you to the documents that are often hard to find. The section of translation should provide a general enough overview of common mistakes and pitfalls. We have found the localisation community very fragmented and hope that through this document we can bring people together and unify information that is out there but in many many different places. The one section that we feel is unique is the guide to developers – they make assumptions about localisation without fully understanding the implications, we complain but honestly there is not one place that can help give a developer and overview of what is needed from them, we hope that the developer section goes a long way to solving that issue. 1.1 Purpose The purpose of this document is to provide one reference for localisers. You will find lots of information on localising and packaging on the web but not a single resource that can guide you. Most of the information is also domain specific ie it addresses KDE, Mozilla, etc. We hope that this is more general. This document also goes beyond the technical aspects of localisation which seems to be the domain of other lo- calisation documents.
    [Show full text]
  • Design and Implementation of an End-User Programming Software System to Create and Deploy Cross-Platform Mobile Mashups
    Degree Project Design and implementation of an end-user programming software system to create and deploy cross-platform mobile mashups Sandra Kaltofen 2010-11-09 Subject: Computer Science Level: Bachelor Course code: DA3003 Abstract Significant changes in mobile computing are continuously influenced by the enhanced features of mobile devices and software applications. The release of open platforms that allow the creation of advanced mobile applications are the triggers for recent developments with regard to the topics of end-user mobile application frameworks and mobile mashup creation. Inspired by these efforts, this thesis identifies some of the problems in this field and presents a solution for a cross-platform end-user programming software system that enables the creation of mobile mashups. Keywords: Android, Cross-platform mobile frameworks, Google Web Toolkit, iPhone, Java, JavaScript, Mashups, Mobile mashups, Web 2.0 APIs, Web development frameworks ii Table of Contents 1 Introduction ................................................................................................................ 1 1.1 Definition of the problem .................................................................................... 3 1.2 Structure of the thesis .......................................................................................... 3 1.3 Delimitations ....................................................................................................... 4 2 State of the art............................................................................................................
    [Show full text]
  • Revisiting XSS Sanitization
    Revisiting XSS Sanitization Ashar Javed Chair for Network and Data Security Horst G¨ortzInstitute for IT-Security, Ruhr-University Bochum [email protected] Abstract. Cross-Site Scripting (XSS) | around fourteen years old vul- nerability is still on the rise and a continuous threat to the web applica- tions. Only last year, 150505 defacements (this is a least, an XSS can do) have been reported and archived in Zone-H (a cybercrime archive)1. The online WYSIWYG (What You See Is What You Get) or rich-text editors are now a days an essential component of the web applications. They allow users of web applications to edit and enter HTML rich text (i.e., formatted text, images, links and videos etc) inside the web browser window. The web applications use WYSIWYG editors as a part of comment functionality, private messaging among users of applications, blogs, notes, forums post, spellcheck as-you-type, ticketing feature, and other online services. The XSS in WYSIWYG editors is considered more dangerous and exploitable because the user-supplied rich-text con- tents (may be dangerous) are viewable by other users of web applications. In this paper, we present a security analysis of twenty five (25) pop- ular WYSIWYG editors powering thousands of web sites. The anal- ysis includes WYSIWYG editors like Enterprise TinyMCE, EditLive, Lithium, Jive, TinyMCE, PHP HTML Editor, markItUp! universal markup jQuery editor, FreeTextBox (popular ASP.NET editor), Froala Editor, elRTE, and CKEditor. At the same time, we also analyze rich-text ed- itors available on very popular sites like Twitter, Yahoo Mail, Amazon, GitHub and Magento and many more.
    [Show full text]
  • Cherrypy Documentation Release 10.0.1.Dev0+Ng4134282.D20170207
    CherryPy Documentation Release 10.0.1.dev0+ng4134282.d20170207 CherryPy Team February 07, 2017 Contents 1 Foreword 1 1.1 Why CherryPy?.............................................1 1.2 Success Stories..............................................2 2 Installation 5 2.1 Requirements...............................................5 2.2 Supported python version........................................5 2.3 Installing.................................................5 2.4 Run it...................................................6 3 Tutorials 9 3.1 Tutorial 1: A basic web application...................................9 3.2 Tutorial 2: Different URLs lead to different functions.......................... 10 3.3 Tutorial 3: My URLs have parameters.................................. 11 3.4 Tutorial 4: Submit this form....................................... 12 3.5 Tutorial 5: Track my end-user’s activity................................. 12 3.6 Tutorial 6: What about my javascripts, CSS and images?........................ 13 3.7 Tutorial 7: Give us a REST....................................... 15 3.8 Tutorial 8: Make it smoother with Ajax................................. 17 3.9 Tutorial 9: Data is all my life...................................... 19 3.10 Tutorial 10: Make it a modern single-page application with React.js.................. 22 3.11 Tutorial 11: Organize my code...................................... 25 4 Basics 27 4.1 The one-minute application example.................................. 28 4.2 Hosting one or more applications...................................
    [Show full text]
  • Learning Django Web Development
    www.it-ebooks.info Learning Django Web Development From idea to prototype, a learner's guide for web development with the Django application framework Sanjeev Jaiswal Ratan Kumar BIRMINGHAM - MUMBAI www.it-ebooks.info Learning Django Web Development Copyright © 2015 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: June 2015 Production reference: 1150615 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78398-440-4 www.packtpub.com www.it-ebooks.info Credits Authors Copy Editors Sanjeev Jaiswal Brandt D'mello Ratan Kumar Neha Vyas Reviewers Project Coordinator Michael Giuliano Nikhil Nair Danijel Pančić Martin Pernica Proofreader Safis Editing Vikash Verma Indexer Commissioning Editor Mariammal Chettiyar Julian Ursell Production Coordinator Acquisition Editors Nilesh R.
    [Show full text]
  • Jinja2 Documentation Release 2.9.6 September 29, 2017
    Jinja2 Documentation Release 2.9.6 September 29, 2017 Contents I Jinja2 Documentation1 1 Introduction3 2 API 7 3 Sandbox 39 4 Template Designer Documentation 45 5 Extensions 85 6 Integration 103 7 Switching from other Template Engines 105 8 Tips and Tricks 111 II Additional Information 115 9 Frequently Asked Questions 117 10 Jinja2 Changelog 121 i ii Part I JINJA2 DOCUMENTATION 1 2 CHAPTER 1 Introduction This is the documentation for the Jinja2 general purpose templating language. Jinja2 is a library for Python that is designed to be flexible, fast and secure. If you have any exposure to other text-based template languages, such as Smarty or Django, you should feel right at home with Jinja2. It’s both designer and developer friendly by sticking to Python’s principles and adding functionality useful for tem- plating environments. Prerequisites Jinja2 works with Python 2.6.x, 2.7.x and >= 3.3. If you are using Python 3.2 you can use an older release of Jinja2 (2.6) as support for Python 3.2 was dropped in Jinja2 version 2.7. If you wish to use the PackageLoader class, you will also need setuptools or distribute installed at runtime. Installation You have multiple ways to install Jinja2. If you are unsure what to do, go with the Python egg or tarball. 3 As a Python egg (via easy_install) You can install the most recent Jinja2 version using easy_install or pip: easy_install Jinja2 pip install Jinja2 This will install a Jinja2 egg in your Python installation’s site-packages directory.
    [Show full text]
  • Tinymce Asp Net Mvc Example
    Tinymce Asp Net Mvc Example Jessee is lessened: she derate doubtless and belabour her pikestaff. Substernal Moe serenades no grubbers compelled diametrically after Ivan hypothecating equally, quite arty. Is Jeromy professorial or enunciable after reachable Gerhard Latinise so analogically? Otherwise we should be removed when i pass that can be displayed in an extension method. Tries to their job of these references must be working for a dropdown, they often comes an episerver world has more! You could not looks similar mask for this needs is an object which help you can be customized search service or suggestions and website? One method and a div with html encode data arrays as i interviewed about? In our subscribers list for other links using firebug for. Model binder should review content. Written immediately deleted as guide for production and asking for. In the cdn script on some top section of your page into the database created by the project then editor? Previous product next thing is not accept server. Parece que el enlace que esta página de alguna manera pasarle las credenciales o un sitio desarrollado en una página muestre un token. Adding the image, we offer any more. Url part is this info with javascript framework that one can now, wiki syntax highlighter extension method. Google code that editors can be as it mean by me know it possible security in place on how grepper helps. It showed only your efforts easier, tinymce asp net mvc example of your code, parsable html then i would be? The document inside an example of an iframe is to.
    [Show full text]
  • Xwiki Standard 9.8.1 User Guide Xwiki Standard 9.8.1 User Guide
    XWiki Standard 9.8.1 User Guide XWiki Standard 9.8.1 User Guide Table of Contents Pages Overview .................................................................................................................................................................... 3 XWiki Applications Overview .......................................................................................................................................... 108 Other XWiki Applications Overview ................................................................................................................................ 217 Users and Groups Overview ............................................................................................................................................. 231 Page 2 XWiki Standard 9.8.1 User Guide • Pages Overview • Create a Wiki Page • Simple and Advanced Edit • Common Edit Actions • Editing Modes • XWiki Syntaxes • The CKEditor • Nested Page Actions • Share Page By Email • Page Comments • Page Attachments • Page History • Page Export Formats • Internationalization • Activity Stream • Keyboard Shortcuts • XWiki Applications Overview • Annotations Application • Dashboard Application • Flamingo Skin • Help Center Application • Index Application • Office Importer Application • Search Application • Syntax Highlighting Application • Tag Application • Tour Application • Other Applications • Blog Application • Users and Groups Overview • Registration • Login • User Profile • User Preferences • User Status • Join a Sub-Wiki • Wiki Invitations
    [Show full text]