Skip to content

Instantly share code, notes, and snippets.

@adamgoose
Created January 10, 2015 00:20
Show Gist options
  • Save adamgoose/7434b680b96c23e36dbd to your computer and use it in GitHub Desktop.
Save adamgoose/7434b680b96c23e36dbd to your computer and use it in GitHub Desktop.
BridgeConX Plugin Documentation

BridgeConX Plugins

Creating a new BridgeConX Plugin will involve you cloning this repository, and committing it to a new one with a proper name. All BridgeConX plugins must be named plugin-{PLUGIN_NAME}.

Setting up composer.json

  1. Edit the name property. Change "template" to your package name.
  2. Update the description property.
  3. Feel free to add yourself as an author.
  4. Update the namespace under autoload.psr-4 to reflect your plugin's namespace. For example, if you are writing a YouTube plugin, you may namespace it BridgeConX\\YouTube\\.

Setting up your Service Provider

Rename the src/TemplateServiceProvider.php to reflect your plugin's name. For example, if you are writing a YouTube plugin, you may call it src/YouTubeServiceProvider.php.

Plugin Registration

Next, update the call to $this->plugin($name) in the public function register() to reflect your plugin's name. This MUST match the {PLUGIN_NAME} used to define your composer package name.

A BridgeConX\Exceptions\PluginNotRegistered exception will be thrown if you do not call $this->plugin($name) inside the PluginServiceProvider's register() method.

This will do four things:

  1. Register your routes file (located at /src/routes.php) with a route prefix of $name.
  2. Register your acl file (located at /src/acl.php), which will allow your plugin to register permissions into the Acl System.
  3. Register a view namepsace called bridgeconx-$name to your views folder (located at /views).
  4. Call the registerMenuItems() and registerWidgets() methods at the appropriate time, once

Routes

See the (Laravel Documentation)[http://laravel.com/docs/master/routing] for information on routing. More information is in the example /src/routes.php in this repository.

The $router variable is available to you as an instance of the Laravel Router.

All of your routes will be prefixed with your plugin name. For example, if you are building a YouTube plugin named youtube, and you register a route for view, the actual route will be /youtube/view

Acl (Permissions)

See the (BeatSwitch Lock Documentation)[https://github.com/BeatSwitch/lock] for information on Acl Permissions. More information is in the example /src/acl.php in this repository.

The $lock variable is available to you as an instance of the Acl repository.

In your controllers, you can check against permissions using the \BridgeConX\Plugin\Acl\Facades\Acl facade, also available at \Acl.

  public function getIndex()
  {
    if(\Acl::can('view', 'youtube-videos'))
    {
      return view('bridgeconx-youtube::index');
    }
  }

Menu Items

In the registerMenuItems() method, you can attach menu items to the master Menu Collection by calling $this->menu->add(MenuItem $menuItem).

MenuItems can be instantiated by using the static named, which has the following method signature:

  public static function make($title, $url, $icon, $pattern = null)

The $icon represents a font-awesome icon to render (without the fa class, just fa-foo) class name.

Widgets

Likewise, in the registerWidgets() method, you can attach widgets to the master Widget Collection by calling the $this->widget->add(Widget $widget).

Widgets can be instantiated by using the constructor, which has the following method signature:

  public function __construct($title, $slug, $view, $getData = null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment