Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding plugin templates, plugin installed via composer #11910

Closed
1 of 3 tasks
ivanamat opened this issue Apr 7, 2018 · 7 comments
Closed
1 of 3 tasks

Overriding plugin templates, plugin installed via composer #11910

ivanamat opened this issue Apr 7, 2018 · 7 comments
Assignees
Milestone

Comments

@ivanamat
Copy link

ivanamat commented Apr 7, 2018

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 3.5

  • Platform and Target: Win, OSX, Linux

What happened

In the documentation, where explain how to override plugin template, explain two options, plugins inside plugins folder, and plugins installed via composer. When i try override a plugin template installed vía composer, as described in the manual, it does not work. To override a plugin templates installed via composer, need to do as a plugin inside plugins folder.

src/Template/Plugin/ContactManager/Contacts/index.ctp

Creating this file would allow you to override plugins/ContactManager/src/Template/Contacts/index.ctp.

If your plugin is in a composer dependency (i.e. ‘TheVendor/ThePlugin’), the path to the ‘index’ view of the Custom controller will be:

src/Template/Plugin/TheVendor/ThePlugin/Custom/index.ctp

What you expected to happen

As @markstory comment in this issue:

The documentation should be how the code is working

@markstory markstory added this to the 3.5.15 milestone Apr 8, 2018
@markstory markstory added the view label Apr 8, 2018
@markstory markstory self-assigned this Apr 8, 2018
@markstory markstory modified the milestones: 3.5.15, 3.6.1, 3.6.2. Apr 14, 2018
@markstory
Copy link
Member

I got around to looking at this today, and was able to override a vendored plugin view without issues. My scenario was as follows:

  1. I created a plugin with bake plugin Company/Contacts, and added a controller with only an empty method:
<?php
namespace Company\Contacts\Controller;

use Company\Contacts\Controller\AppController;

class AddressesController extends AppController
{
    public function index()
    {
    }
}
  1. Add a route to routes.php:
    $routes->get('/addresses', ['plugin' => 'Company/Contacts', 'controller' => 'Addresses', 'action' => 'index']);
  1. Create plugin template path - plugins/Company/Contacts/src/Template/Addresses/index.ctp, which is displayed by going to /addresses.
  2. App override template - src/Template/Plugin/Company/Contacts/Addresses/index.ctp, which is displayed by going to /addresses

The names used in the documentation aren't very clear. I'll improve them.

markstory added a commit to cakephp/docs that referenced this issue Apr 22, 2018
@markstory
Copy link
Member

Closing as I wasn't able to reproduce.

@ivanamat
Copy link
Author

Hi @markstory

The problem is not in the plugins created with "bake", it is in the plugins installed via composer.

  1. Install http://github.com/ivanamat/cakephp3-aclmanager
  2. Configure the plugin
  3. The plugin routes in vendor/ivanamat/cakephp3-aclmanager/config/routes.php are:
    Router::connect('AclManager', ['plugin' => 'AclManager', 'controller' => 'Acl', 'action' => 'index'] );
    Router::connect('AclManager/:action/*',['plugin' => 'AclManager', 'controller' => 'Acl']);

  1. Create plugin template path as described in the docs

If your plugin is in a composer dependency (i.e. ‘TheVendor/ThePlugin’), the path to the ‘index’ view of the Custom controller will be: src/Template/Plugin/TheVendor/ThePlugin/Custom/index.ctp

It does not work

src/Template/Plugin/ivanamat/AclManager/Acl/index.ctp

It does not work

src/Template/Plugin/ivanamat/AclManager/index.ctp

it works!

src/Template/Plugin/AclManager/Acl/index.ctp

I think that is not what is detailed in the documentation.

Maybe there is something wrong in this plugin? If there is, what is it?

Regards!

@ivanamat
Copy link
Author

Hi @markstory

In relation with improving cakephp/docs@3ee74aa

Company is VendorName? in my case, ivanamat?

@ADmad
Copy link
Member

ADmad commented Apr 22, 2018

You haven't used a vendor name in your namespace https://github.com/ivanamat/cakephp3-aclmanager/blob/bc6cfe9745ea5f7aae7da73a0cc6d976cbc57225/composer.json#L24 Hence src/Template/Plugin/AclManager/Acl/index.ctp is the expected path for you.

@ivanamat
Copy link
Author

Hi @ADmad

Then, It should be?

"autoload": {
        "psr-4": {
            "ivanamat\\AclManager\\": "src"
        }
    }

Thnx!

@ADmad
Copy link
Member

ADmad commented Apr 22, 2018

It doesn't have to be. Using vendor name at top level in your namespace is optional. For example core plugins like DebugKit, Bake don't use it. If you do use vendor name then it should be camel cased so Ivanamat\AclManager not ivanamat\AclManager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants