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

CraftCMS Driver canBootstrap function detects wrong file path #250

Closed
johnwbaxter opened this issue Jul 10, 2020 · 3 comments
Closed

CraftCMS Driver canBootstrap function detects wrong file path #250

johnwbaxter opened this issue Jul 10, 2020 · 3 comments

Comments

@johnwbaxter
Copy link

@johnwbaxter johnwbaxter commented Jul 10, 2020

Hi, your CraftCMS driver wont work? for most people due to the detection you are doing here: https://github.com/tinkerwellapp/drivers/blob/master/src/Drivers/CraftTinkerwellDriver.php on line 13:

return file_exists($projectPath . '/web/index.php') &&

"web" is the suggested directory but 99% of people will change that to "public" or "public_html" so you can't use that as detecting if it's bootstrappable or not.

It would be really nice if you could make a 1 min video or a really really short guide just showing the total absolute basics on interacting with Craft with Tinkwerwell in this way too. But certainly, changing how that bootstrap detection works would make it work with my projects which would be really helpful too :)

@sschlein
Copy link
Member

@sschlein sschlein commented Jul 10, 2020

@johnwbaxter

The driver itself was provided from the community as we don't have specific CraftCMS knowledge – so it's hard to create a video that shows the benefits. This might be an opportunity for someone :)

The driver that you have linked might not be included in the recent release. It needs to be compiled into the app and this requires a new update for Tinkerwell. I got some reports that it works if you use a custom driver - this also allow you to change the directory for detection.

https://tinkerwell.app/tutorials/3-how-to-write-a-custom-tinkerwell-driver

@johnwbaxter
Copy link
Author

@johnwbaxter johnwbaxter commented Jul 10, 2020

@sschlein I found this just after I posted the issue so am just working through the code to make my own driver here. If I can at least get tinkerwell to detect Craft, then I can probably work out how to use it :) Need to get past this first hurdle though :)

@johnwbaxter
Copy link
Author

@johnwbaxter johnwbaxter commented Jul 10, 2020

@sschlein Well, that was really easy!! I created the custom driver overriding the canBootStrap method to set the correct path and we're in! Really really nice!! Thanks!!

So for reference to others, I just created a .tinkerwell folder at the same level as your craft install (i.e same level as your public folder) and then created a file in that folder called "customCraftTinkerwellDriver.php" and put the below code in it.

<?php
use Tinkerwell\ContextMenu\SetCode;

class customCraftTinkerwellDriver extends CraftTinkerwellDriver
{
    /**
     * Determine if the driver can be used with the selected project path.
     * You most likely want to check the existence of project / framework specific files.
     *
     * @param string $projectPath
     * @return bool
     */
    public function canBootstrap($projectPath)
    {
        return file_exists($projectPath . '/public/index.php') &&
            file_exists($projectPath . '/craft');
    }

}

Then open Tinkerwell and set the working directory to be the directory your site is (not your public folder, the folder above that) and then you are right in.

You can get straight to coding, just try typing this in the left hand column: Craft::$app->config->general->cpTrigger and it will return the cpTrigger value in the right hand column, no need to add any other code first, or any other scaffolding code that you normally would in a plugin or module to at least be able to run that. You may of course need to for other code you may write!!

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.