Currently the getFile() function returns a fixed path starting with '/libraries/. Similarly the getButtons() function returns a fixed path to the images starting with '/libraries'. This does not work when Drupal is installed at a subdirectory to the domain (e.g. http://localhost/drupal8/libraries).

I also found this is very similar to another project on github: https://github.com/wwalc/colorbutton. I suspect even shared the same start at some point. That code currently solves this with code like this:

function getFile() {
    return drupal_get_path('module', 'colorbutton') . '/js/plugins/colorbutton/plugin.js';
  }

Should this module and the one I found on github be merged or ??? I can copy/paste things and I'm willing to help but that doesn't mean I know what I'm doing. I'm certainly not capable of maintaining the module itself, but hoping that having found some simple fix is respectful of what you have done arleady and will make it easy for you to do a quick fix.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

carteriii created an issue. See original summary.

carteriii’s picture

For what it's worth, the addition of base_path() appears to fix the immediate problem I see:

public function getFile() {
    return base_path() . '/libraries/colorbutton/plugin.js';
  }

It doesn't appear that Drupal 8 supports a call to drupal_get_path('library', 'colorbutton') which would have been even better than assuming the library is at the root level. I libraries module provides an API to get the library path but that seems like overkill to add the libraries module for this.

kevinquillen’s picture

Hi carter, you are correct, I did see the other Color Button module and learned how to integrate plugins from that. I added in the ability to restrict colors from the admin and had future plans to also implement Color Panel as a sub module, as this was a recent requirement for a project. I did not put the plugins into the module because of the rules surrounding third party code packaged up within a Drupal module.

I don't think I have ever installed Drupal as a sub directory so I usually forget to do this. I will implement base_path() to resolve the issue.

Also, regarding Libraries, no I would prefer not to require a dependency to do this. libraries in the root is mentioned in the core documentation for this purpose, even if it is not auto-discoverable. In the future, if necessary, I will adapt to fit the need.

kevinquillen’s picture

Assigned: Unassigned » kevinquillen
kevinquillen’s picture

Attaching patch

kevinquillen’s picture

Status: Active » Needs review
carteriii’s picture

That same approach needs to be applied to getButtons. For example, this is what I did:

  public function getButtons() {
    return [
      'TextColor' => array(
        'label' => t('Text Color'),
        'image' => base_path() . '/libraries/colorbutton/icons/textcolor.png',
      ),
      'BGColor' => array(
        'label' => t('Background Color'),
        'image' => base_path() . '/libraries/colorbutton/icons/bgcolor.png',
      ),
    ];
  }

For what it's worth, this same/similar change needs to be applied to pannelbutton as well.

carteriii’s picture

I forgot to say, "Thank you!"

kevinquillen’s picture

Should it be base_path() or DRUPAL_ROOT?

kevinquillen’s picture

kevinquillen’s picture

Updating patch

carteriii’s picture

I think base_path(), but I'm not 100% certain. Doesn't DRUPAL_ROOT include the server director? For example, would DRUPAL_ROOT return "/var/www/drupal8"? If so, we don't want that because we're trying to create a URL and the URL would never reference "/var/www". We really just want the "/drupal8" such that, if using localhost without any subdomain, the URL would be http://localhost/drupal8/.... You'd never want a URL that was "http://localhost/var/www/drupal8"

kevinquillen’s picture

Alright, lets go with this then. Just wanted to check.

kevinquillen’s picture

Status: Needs review » Reviewed & tested by the community

  • kevinquillen committed 052b152 on 8.x-1.x
    Fixes [#2717655] with respect to Drupal installed in sub directories.
    
kevinquillen’s picture

Status: Reviewed & tested by the community » Fixed

Pushed to dev.

kevinquillen’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.