Agiledrop Resources

website·Indexed 34 days ago

https://resources.agiledrop.com/docs/

A collection of technical documentation and guides for Drupal and WordPress development. Includes code snippets and tutorials for Drupal entity rendering, migrations, and Cache API, as well as WordPress REST API registration, custom post types, and action hooks. Also provides DevOps resources for Docker and general deployment checklists.

Tokens
17.8K
Snippets
127
Records
181
Agent score
50%

What's inside Agiledrop

  1. Implement user notifications using the Message module

    Use the Message module to create a notification system. This involves:

    1. Adding a preference field to the user profile (e.g., 'Notify me about new events').
    2. Triggering a message when a new entity is created.
    3. Displaying notifications via a View block or a custom block plugin.
    4. Using hook_views_query_alter to dynamically change the number of results in the notification view based on user profile settings.
  2. Programmatically run or rollback a Drupal migration

    To execute a migration programmatically in Drupal, use the plugin.manager.migration service to create a migration instance and then use MigrateExecutable to perform the import. To perform an update migration, call prepareUpdate() on the ID map. To perform a rollback instead of an import, call the rollback() method on the executable object.
    // Create the migration instance using the machine name
    $migration = \Drupal::service('plugin.manager.migration')->createInstance('machine_name');
    
    // Call prepareUpdate() specifically for update migrations; omit for normal imports
    $migration->getIdMap()->prepareUpdate();
    
    $executable = new \Drupal\migrate_tools\MigrateExecutable($migration, new \Drupal\migrate\MigrateMessage());
    
    // Use import() to run the migration, or rollback() to reverse it
    $executable->import();
  3. Complete the macOS installation process

    Once in the main recovery UI, select the offered macOS version for reinstallation. If installing the latest version, ensure you are connected to Wi-Fi via the icon in the top right corner. Accept the Terms and Conditions to begin the installation.
  4. Create a custom WordPress widget by extending WP_Widget

    To create a custom widget in WordPress, you must extend the WP_Widget class. The constructor is used to define the widget's base ID, display name, and a description.
    class Agiledrop_Widget extends WP_Widget {
        public function __construct() {
            parent::__construct(
                'agiledrop_widget', // Base ID
                'Agiledrop Widget',  // Name
                array( 'description' => 'Select categories and display theirs title.' )
            );
        }
    }
  5. Set up Drupal development environment and coding standards

    Before developing for Drupal, ensure you adhere to the official Drupal Coding Standards and configure your IDE for optimal productivity. Key resources include:

    • Coding Standards: Review the official Drupal Coding Standards for general PHP and JavaScript guidelines.
    • IDE Setup: Use PhpStorm with the dedicated Drupal development configuration to simplify development.
    • Theming: Familiarize yourself with the theme folder structure and Twig template naming conventions for Drupal 8 and 7.
    • JavaScript: Follow the Drupal JavaScript coding standards.
  6. Register a custom function using a WordPress action

    Use the add_action() function to hook a custom callback function into a specific WordPress event. This allows you to execute code at precise moments, such as when scripts and styles are being enqueued.
    function register_style() {
        wp_enqueue_style( 'agiledrop-style', get_stylesheet_uri(), array(), '1.0.0', 'all' );
    }
    
    add_action( 'wp_enqueue_scripts', 'register_style' );
  7. Erase and prepare MacBook drives for OS installation

    Within the recovery menu, use 'Disk Utilities' to wipe all existing partitions. If the drive has multiple partitions, erase them all and create a single new volume using the '+' button, assigning all available space. Use the first available format type (non-encrypted). After preparation, exit Disk Utility to return to the main UI.
  8. Configure Infinite Scroll and 'Load More' buttons in Views

    To replace standard pagers with dynamic loading, use the views_infinite_scroll module:

    • Infinite Scroll: Configure the /events page to automatically load more items as the user reaches the bottom of the screen.
    • Load More Button: Configure the /companies page to use a 'Load more' button that fetches additional items (e.g., 6 items per click) instead of automatic loading.
    # Module link
    https://www.drupal.org/project/views_infinite_scroll
  9. Implement a custom suggestion form with conditional fields

    Create a custom form (e.g., at /suggest-location) restricted to registered users. Use the Form API to implement conditional fields (e.g., showing a text input only when a specific radio button option like 'Other' is selected). Upon submission, the form should programmatically generate an unpublished node and notify users with a specific administrative role (e.g., 'Suggestions Admin') via email.
  10. Test custom entities and services in Drupal

    Use the following testing strategies for Drupal components:

    • Unit Tests: Use PHPUnit to test isolated services (e.g., a service calculating days until an event).
    • Functional/Behat Tests: Use these to verify that configuration forms and UI workflows function correctly.
    • Mocking: Mock external API requests (e.g., NewsAPI) to test data processing and database persistence without relying on live external services.
    • CRUD Tests: Write tests specifically to confirm that Create, Read, Update, and Delete operations on custom entity types (like 'Review') work as expected.
  11. Build multi-step forms with the Webform module

    The Webform module can be used to create complex user-facing forms. For a multi-step contact and feedback form:

    • Step 1 (Contact): Include fields for First Name, Last Name, Company, Contact Email, Phone Number, and Message.
    • Step 2 (Feedback): Include fields for product satisfaction, recommendation likelihood, and age ranges (e.g., 0-18, 19-30, 31-50).
  12. Create a custom form within a block using Form API

    You can embed a form inside a custom block to perform actions like 'Send to a friend'.

    • Form API: Define the form elements (mandatory name and email fields).
    • Validation: Implement validation logic to ensure the email is valid.
    • Submission: Use Drupal's email system to send the notification upon successful validation.
    • AJAX: Upgrade the form to use AJAX submission to avoid full page reloads.