# Google Drive addon

**URL:** <https://discourse.getcockpit.com/t/google-drive-addon/1896>\
**Category:** Addons\
**Created:** [April 3, 2021, 1:50pm UTC](https://discourse.getcockpit.com/t/google-drive-addon/1896 "2021-04-03T13:50:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)\
**Post date:** [April 6, 2021, 1:06pm UTC](https://discourse.getcockpit.com/t/google-drive-addon/1896/2 "2021-04-06T13:06:46Z")

</div>

Hello @VirHeroicus,

> [@VirHeroicus](#):
>
> `$app->path('googledrive', 'addons/GoogleDrive/');`

You don’t need that line. Paths for addons/modules follow a naming pattern. Let’s assume the following folder structure:

```plaintext
.
├── addons/
│ └── GoogleDriveConnector/
│ ├── assets/
│ | ├── style.css
│ | └── script.js
│ ├── Controller/
│ | └── Admin.php
│ ├── Helper/
│ ├── views/
│ | └── index.php
│ ├── bootstrap.php
│ └── admin.php

```

For `$app->path()`, the folder name is case insensitive. For Controllers and Helpers (classes), proper casing is mandatory.

```php
$path = $app->path('googledriveconnector:views/index.php');
# /var/www/virtual/user/html/addons/GoogleDriveConnector/views/index.php

$path = $app->pathToUrl('googledriveconnector:views/index.php');
# /addons/GoogleDriveConnector/views/index.php

```

The Admin controller can be autoloaded.

**Controller/Admin.php:**

```php
<?php

// must match the folder name!
namespace GoogleDriveConnector\Controller;

class Admin extends \Cockpit\AuthController {

    public $data = [
        'don\'t be evil' => false,
        'GDPR-compliant' => false,
        'spyware' => 'kind of',
        'alternatives' => [
            'Drive' => ['Nextcloud'],
            'Docs' => ['Etherpad', 'OnlyOffice'],
        ],
    ]

    public function index() {

        return $this->render('googledriveconnector:views/index.php', ['data' => $this->data]);

    }

    public function getData() {

        return $this->data;

    }

}

```

**admin.php:**

```php
<?php

$this->on('admin.init', function() {

    // add assets
    $this->helper('admin')->addAssets([
        'googledriveconnector:assets/style.css',
        'googledriveconnector:assets/script.js',
    ]);

    // bind admin routes
    // --> "/gdc" points to index()
    // --> "/gdc/getData" points to getData()
    $this->bindClass('GoogleDriveConnector\\Controller\\Admin', 'gdc');

});

```

> [@VirHeroicus](#):
>
> 1/ how in all heavens do you make your additionnal assets (css and js) load and work?

see above

> [@VirHeroicus](#):
>
> `include_once( __DIR__. '/admin.php');`

Code inside `admin.php` is only for backend access, so don’t load it if you don’t need it. The name has nothing to do with the “admin” group permission.

```php
if (COCKPIT_ADMIN_CP) include_once( __DIR__. '/admin.php');

```

> [@VirHeroicus](#):
>
> `$app->on("admin.dashboard.widgets", function($widgets) {`

Don’t start with widgets, if you want to learn Cockpit. Create pages and routes, call them directly in your browser to see the json responses. If your core logic works, think about widgets. Be aware, that widgets have a drag event by default.

> [@VirHeroicus](#):
>
> 2/ How do you access data contained in a specific singleton? Do you make an… api call?

```php
$config = $app->module('singletons')->getData('name-of-singleton');

```

see: [https://github.com/agentejo/cockpit/blob/next/modules/Singletons/bootstrap.php#L136](https://github.com/agentejo/cockpit/blob/next/modules/Singletons/bootstrap.php#L136)

**Further notes:**

It looks like you used the Groups addon for inspiration. It isn’t very well structured (at least to get started). I think, this one is easier for understanding the folder and path structure:

> **[GitHub - raffaelj/cockpit\_ImageResize: Addon for Cockpit CMS to resize...](https://github.com/raffaelj/cockpit_ImageResize)**
>
> Addon for Cockpit CMS to resize uploaded images automatically - GitHub - raffaelj/cockpit\_ImageResize: Addon for Cockpit CMS to resize uploaded images automatically

**More resources:**

> [@How to create a addon](https://discourse.getcockpit.com/t/how-to-create-a-addon/345/6):
>
> Cockpit has a lot of ways to get modified. A few of them are documented. If you read anything in the issues or in this forum about adding code to config/bootstrap.php, this same code could be in an addon with the same effect. The difference here is, if you want to modify it fast and simple or if you want to provide a reusable addon. Addons are handled the same like core modules (collections, singletons, forms). So, each addon will be auto-registered as a cockpit module. Theoretically, there is …

> <https://github.com/agentejo/cockpit/blob/next/lib/Lime/App.php#L1106-L1137>

> <https://github.com/agentejo/cockpit/blob/next/lib/Lime/App.php#L118-L130>

> <https://github.com/agentejo/cockpit/blob/next/lib/Lime/App.php#L352-L391>

---

_[View the full topic](https://discourse.getcockpit.com/t/google-drive-addon/1896)._
