{"_id":"57fa2b922996241700c7c1ce","version":{"_id":"57b80485f442340e00b01701","project":"56363c690441020d0000e9da","__v":1,"createdAt":"2016-08-20T07:19:33.761Z","releaseDate":"2016-08-20T07:19:33.761Z","categories":["57b80485f442340e00b01702","57b80485f442340e00b01703","57b80485f442340e00b01704","57b80485f442340e00b01705","57b80485f442340e00b01706","57b80485f442340e00b01707","57b80485f442340e00b01708","57b80485f442340e00b01709","57b80485f442340e00b0170a","57b80485f442340e00b0170b"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0-dev","version":"1.0.0-dev"},"parentDoc":null,"user":"55d48e9283130a250029b3cd","__v":0,"category":{"_id":"57b80485f442340e00b01708","version":"57b80485f442340e00b01701","__v":0,"project":"56363c690441020d0000e9da","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-11-01T16:28:32.608Z","from_sync":false,"order":6,"slug":"extending","title":"Extending"},"project":"56363c690441020d0000e9da","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-10-09T11:35:46.961Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"Lets start create an extension, a Plugin in this case:\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"1. Create a extension\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php namespace MyNamespace\\\\BarPlugin;\\n\\n\\nuse Mascame\\\\Artificer\\\\Plugin\\\\AbstractPlugin;\\n\\n\\nclass BarPlugin extends AbstractPlugin {\\n\\n    /**\\n     * This will be called if the plugin is installed\\n     */\\n    public function boot()\\n    {\\n        // We will be able to do something here once the plugin is installed by the client    \\n    }\\n\\n}\",\n      \"language\": \"php\",\n      \"name\": \"BarPlugin.php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"2. Adding the ServiceProvider\"\n}\n[/block]\nThe ServiceProvider **takes care of registering plugins & widgets** under a package namespace.\n\nYou must extend *ArtificerExtensionServiceProvider* and indicate the *$package*.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"What is $package?\",\n  \"body\": \"You can add multiple extensions (plugins and/or widgets) in the same repository for convenience. That's why we need to unify them under a name, in this case that name is the *$package* property.\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php namespace MyNamespace\\\\BarPlugin;\\n\\nuse MyNamespace\\\\BarPlugin\\\\BarPlugin;\\n\\nclass BarPluginServiceProvider extends ArtificerExtensionServiceProvider {\\n\\n    protected $package = 'my-namespace/bar-plugin';\\n\\n    public function register()\\n    {\\n        $this->addPlugin(BarPlugin::class);\\n    }\\n\\n}\\n\",\n      \"language\": \"php\",\n      \"name\": \"BarPluginServiceProvider.php\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Adds *addPlugin* & *addWidget* methods and hides the methods of ServiceProvider that must not be used. That will let us focus on what matters and avoid errors.\",\n  \"title\": \"Extends ArtificerExtensionServiceProvider\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"3. Registering the ServiceProvider\"\n}\n[/block]\nNow that we created the ServiceProvider lets register it:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"'providers' => [\\n        Collective\\\\Html\\\\HtmlServiceProvider::class,\\n        Stolz\\\\Assets\\\\Laravel\\\\ServiceProvider::class,\\n        Mascame\\\\Artificer\\\\DefaultThemeServiceProvider::class,\\n        Mascame\\\\Artificer\\\\InstallServiceProvider::class,\\n        Mascame\\\\Artificer\\\\LoginPluginServiceProvider::class,\\n        Mascame\\\\Artificer\\\\ArtificerWidgetsServiceProvider::class,\\n        Mascame\\\\Artificer\\\\LogReaderPluginServiceProvider::class,\\n        \\n        MyNamespace\\\\BarPlugin\\\\BarPluginServiceProvider::class\\n    ],\",\n      \"language\": \"text\",\n      \"name\": \"config/admin/admin.php\"\n    }\n  ]\n}\n[/block]\nWe successfully created our first plugin!\n\nTo learn more about what you can do with extensions keep reading the **Extending** section.","excerpt":"","slug":"creating-an-extension","type":"basic","title":"Creating an extension"}

Creating an extension


Lets start create an extension, a Plugin in this case: [block:api-header] { "type": "basic", "title": "1. Create a extension" } [/block] [block:code] { "codes": [ { "code": "<?php namespace MyNamespace\\BarPlugin;\n\n\nuse Mascame\\Artificer\\Plugin\\AbstractPlugin;\n\n\nclass BarPlugin extends AbstractPlugin {\n\n /**\n * This will be called if the plugin is installed\n */\n public function boot()\n {\n // We will be able to do something here once the plugin is installed by the client \n }\n\n}", "language": "php", "name": "BarPlugin.php" } ] } [/block] [block:api-header] { "type": "basic", "title": "2. Adding the ServiceProvider" } [/block] The ServiceProvider **takes care of registering plugins & widgets** under a package namespace. You must extend *ArtificerExtensionServiceProvider* and indicate the *$package*. [block:callout] { "type": "info", "title": "What is $package?", "body": "You can add multiple extensions (plugins and/or widgets) in the same repository for convenience. That's why we need to unify them under a name, in this case that name is the *$package* property." } [/block] [block:code] { "codes": [ { "code": "<?php namespace MyNamespace\\BarPlugin;\n\nuse MyNamespace\\BarPlugin\\BarPlugin;\n\nclass BarPluginServiceProvider extends ArtificerExtensionServiceProvider {\n\n protected $package = 'my-namespace/bar-plugin';\n\n public function register()\n {\n $this->addPlugin(BarPlugin::class);\n }\n\n}\n", "language": "php", "name": "BarPluginServiceProvider.php" } ] } [/block] [block:callout] { "type": "info", "body": "Adds *addPlugin* & *addWidget* methods and hides the methods of ServiceProvider that must not be used. That will let us focus on what matters and avoid errors.", "title": "Extends ArtificerExtensionServiceProvider" } [/block] [block:api-header] { "type": "basic", "title": "3. Registering the ServiceProvider" } [/block] Now that we created the ServiceProvider lets register it: [block:code] { "codes": [ { "code": "'providers' => [\n Collective\\Html\\HtmlServiceProvider::class,\n Stolz\\Assets\\Laravel\\ServiceProvider::class,\n Mascame\\Artificer\\DefaultThemeServiceProvider::class,\n Mascame\\Artificer\\InstallServiceProvider::class,\n Mascame\\Artificer\\LoginPluginServiceProvider::class,\n Mascame\\Artificer\\ArtificerWidgetsServiceProvider::class,\n Mascame\\Artificer\\LogReaderPluginServiceProvider::class,\n \n MyNamespace\\BarPlugin\\BarPluginServiceProvider::class\n ],", "language": "text", "name": "config/admin/admin.php" } ] } [/block] We successfully created our first plugin! To learn more about what you can do with extensions keep reading the **Extending** section.