Giter VIP home page Giter VIP logo

plug's Introduction

Build Status Scrutinizer Code Quality Join the chat at https://gitter.im/Plug-Drupal/plug

Plug

Get the plugin system for Drupal 8 in your Drupal 7 developments.

The Plug module is a module for developers that can't wait until Drupal 8 comes out to use the plugin system that will ship with it. You can use this as an alternative to your custom CTools plugins.

Do I need this module?

This is one of those modules that does nothing by itself, but provides tools for developers for a better developer experience. If you write custom PHP code for Drupal in a day to day basis, you can probably take advantage of this module and start writing plugins.

In Drupal 8 everything is a plugin, by starting to write Drupal 8 style plugins today you accomplish two main objectives:

  • Your code is more capable to cope with change, is more maintainable and flexible.
  • You are already learning how you will program for Drupal 8 when it comes out.

Examples

Here you have a couple of examples. The best thing that you can do is read this amazing post about plugins.

Architecture

This module relies on some parts of the Drupal 8 code. Those parts have been encapsulated inside this module to simplify the installation process.

Implementation examples

There is an example module shipped with this module that will show you how to create your plugins and use them.

Things that can be plugins.

Beep-boop-clink-clank, this section is not done just yet. Check back soon!

Situations in which plugins are useful? Anytime you need to allow modules to provide additional "things" that implement the same interface but provide distinctly different functionality. Blocks are the classic example. In Drupal every block consists of essentially the same parts, a label, some content, and various settings related to visibility and cachability. How that label and content is generated is likely very different from one module to the next though. A custom block with static content vs. one provided by Views for example.

Installing

Installation is straightforward. You only need to download and enable the module.

Implementations

The following modules use the Plug module to declare their plugins. If you want your module to be in this list, open an issue.

plug's People

Contributors

e0ipso avatar emisaacson avatar gitter-badger avatar plopesc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plug's Issues

Fatal error when going to the example page

I'm trying this module and when enabling the module example module and i get:
image
Fatal error: Class 'Drupal\Component\Plugin\PluginManagerBase' not found in /var/www/html/drupal/sites/all/modules/plug/src/Core/Plugin/DefaultPluginManager.php on line 22

Can't instantiate a plugin although it's recognised by Plug

I defined a new plugin which need to handled websocket services.

In the library src i added a new file WebSocketPluginManager.php and this is the content:

<?php
class WebSocketPluginManager extends DefaultPluginManager {
  public function __construct(\Traversable $namespaces, \DrupalCacheInterface $cache_backend) {

    parent::__construct('Plugin/websocket', $namespaces, 'Drupal\nuntius\WebSocketInterface', '\Drupal\nuntius\Annotation\WebSocket');
    $this->setCacheBackend($cache_backend, 'websocket_plugins');
    $this->alterInfo('websocket_plugin');
  }

and in the library src/plugin/websocket/ i added the file SocketIoBase.php:

<?php

namespace Drupal\nuntius\Plugin\websokcet;

use Drupal\nuntius\WebSocketInterface;

/**
 * Class SocketIoBase
 * @package Drupal\nuntius\Plugin\websokcet
 *
 * @WebSocket(
 *   id = "socket_io_base",
 *   name = "Socket IO base"
 * )
 */
class SocketIoBase implements WebSocketInterface {

And when I tried to instansiate the plugin:

 $plugin_manager = WebSocketPluginManager::create();
 $plugin_manager->createInstance('socket_io_base');

I got this:

messageDrupal\Component\Plugin\Exception\PluginException: Plugin (socket_io_base) instance class "Drupal\nuntius\Plugin\websocket\SocketIoBase" does not exist. in Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass() (line 102 of /Applications/MAMP/htdocs/drupal/sites/all/modules/plug/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php)

Can't find out the reason for that. The project available here: https://github.com/nuntius-organization/nuntius_drupal

PHP 7 Compatibility

Running php7cc on the Plug code to test for PHP 7 compatibility, a couple of lines of code are flagged. Here are the notices:

File: /var/www/hosting/tellingua/com/htdocs/backend/sites/all/modules/contrib/plug/lib/Symfony/yaml/Symfony/Component/Yaml/Parser.php
> Line 97: Possible object property creation during by-reference assignment
    $parser->refs =& $this->refs;
> Line 106: Possible object property creation during by-reference assignment
    $parser->refs =& $this->refs;
> Line 163: Possible object property creation during by-reference assignment
    $parser->refs =& $this->refs;
> Line 214: Possible object property creation during by-reference assignment
    $parser->refs =& $this->refs;




File: /var/www/hosting/tellingua/com/htdocs/backend/sites/all/modules/contrib/plug/lib/Symfony/validator/Symfony/Component/Validator/Constraints/False.php
> Line 22: Reserved name "false" used as a class, interface or trait name 
    class False extends \Symfony\Component\Validator\Constraints\IsFalse
    {
    }


File: /var/www/hosting/tellingua/com/htdocs/backend/sites/all/modules/contrib/plug/lib/Symfony/validator/Symfony/Component/Validator/Constraints/True.php
> Line 22: Reserved name "true" used as a class, interface or trait name 
    class True extends \Symfony\Component\Validator\Constraints\IsTrue
    {
    }


File: /var/www/hosting/tellingua/com/htdocs/backend/sites/all/modules/contrib/plug/lib/Symfony/validator/Symfony/Component/Validator/Constraints/Null.php
> Line 22: Reserved name "null" used as a class, interface or trait name 
    class Null extends \Symfony\Component\Validator\Constraints\IsNull
    {
    }

Is this something to be concerned about when upgrading to PHP 7 (as I am about to do)?

PHP 8 compatibility

There is fatal error happen when we try to use the module with php8.

PHP Fatal error: Declaration of Doctrine\\Common\\Reflection\\StaticReflectionClass::getConstants() must be compatible with ReflectionClass::getConstants(?int $filter = null) in plug/lib/doctrine/common/lib/Doctrine/Common/Reflection/StaticReflectionClass.php on line 109

I would suggest to apply a patch from doctrine/reflection#49, which actually fixes compatibility issue for doctrine/reflection.

Trying to install plug for the first time, gives an error with the composer manager dependency

When I install plug for the first time, if composer manager is not installed previously, it gives an error, because it doesn't find the composer drush command, after installing the component. Clearing the drush cache, fixes the issue. I'm not sure if it's possible to force that cache clear during the installation.

Here is the output from the shell:

$ drush en plug -y
The following extensions will be enabled: plug
Do you really want to continue? (y/n): y
plug was enabled successfully.                                                                                                                                                [ok]
One or more extensions have dependencies managed by Composer.
Update packages managed by Composer? (y/n): y
Download and install the Drush Composer extension? (y/n): y
Project composer (8.x-1.x-dev) downloaded to ~/.drush/composer.                                                                                                  [success]
Project composer contains 0 modules: .
The drush command 'composer' could not be found.                                                                                                                              [error]
$ drush cc drush
'drush' cache was cleared.                                                                                                                                                    [success]
$ drush | grep composer
Other commands: (colorbox,composer,composer_manager,elysia_cron,redirect,votingapi,l10n_update,libraries,make,menu_import,nodequeue_generate,registry_rebuild,rules,rules_scheduler,schema,strongarm,user_import,uuid,variable_realm,views_bulk_operations,views_data_export,webform,xmlsitemap)
 composer              Perform package management and dependency tracking of your projects and libraries.                                                                       
 composer-json-rebuil  Rebuilds the consolidated composer.json file.                                                                                                            
 d (composer-rebuild,                                                                                                                                                           
 composer-rebuild-fil                                                                                                                                                           
 composer-manager      Executes a composer command in the directory containing the composer.json file.                                                                          
 (composer-execute)                                                                                                                                                             
$ drush dis plug -y
The following extensions will be disabled: plug
Do you really want to continue? (y/n): y
plug was disabled successfully.                                                                                                                                               [ok]
One or more extensions have dependencies managed by Composer.
Update packages managed by Composer? (y/n): y
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing leafo/lessphp (v0.5.0)
    Downloading: 100%         

Writing lock file
Generating autoload files

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.