How to override field_type view?
Created 4 years ago by oimken

Is there a way to override the field_type view file without publish and modified it? I want to add some custom button to markdown-field_type, but I can not override the input.twig in my custom theme (front-end) I have add the overrides line in ServiceProvider of my theme:

    protected $overrides = [
        'anomaly.field_type.markdown::input' => 'oimken.theme.simple::markdown/input',

but nothing happens, maybe field_type priority level is higher ? or I do something wrong? Publish and replace the field_type works, but I really don't like this way.

Anyone know about this? Please help..... Lots of thanks.

ryanthompson  —  4 years ago

Hmm that looks right. You can also place a view in your theme views like addons/anomaly/markdown-field_type/input.twig:

oimken  —  4 years ago

@ ryanthompson I tried. but it does not work... my theme is front-end, is it the reason the overrides not works for backend CP?

ryanthompson  —  4 years ago

Is it set as active? Ill give it a test on my end but I've just recently done this very thing.

ryanthompson  —  4 years ago

Ahh.. ya your theme overrides will only come into play when it's active. So since this is admin I am guessing your public theme overrides will not apply. One sec I'll update that doc on how this should be done.

oimken  —  4 years ago

yes, it's active, only publish markdown field type works, the other ways are all failure. And I also try to make a new custom extension, override it in SeviceProvider and views, does not work,too.

Oh I see, when I am in CP, admin theme is active, so my front-end theme is de-active? but I make a new addon( extension), and installed, does not work, too.

ryanthompson  —  4 years ago
oimken  —  4 years ago
Method add does not exist.

Doc kinda outdate? I think you mean put,

class ViewOverrides extends Collection
     * When putting overrides replace "/" with "."
     * to match the way Laravel interprets views.
     * @param mixed $key
     * @param mixed $value
    public function put($key, $value)
        $overrides = [];
        foreach ($value as $view => $override) {
            $overrides[str_replace('/', '.', $view)] = $override;
        parent::put($key, $overrides);

what's key would be? anomaly.field_type.markdown ? I do this:


Not working.

ryanthompson  —  4 years ago

No use add - and make sure you're up to date. PUT is a mass add.

ryanthompson  —  4 years ago

Very recent addition it looks like actually. That's my bad for not mentioning @oimken

oimken  —  4 years ago

composer update and got the add method, but still..... no luck....

after override I dd($overrides);, I got that overrides but still not work :

ViewOverrides {#1340 ▼
  #items: array:2 [▼
    "pyrocms.theme.starter" => array:2 [▼
      "streams::errors.404" => "theme::errors/404"
      "streams::errors.500" => "theme::errors/500"
    "anomaly.field_type.markdown" => array:1 [▼
      "anomaly.field_type.markdown::input" => "oimken.theme.simple::addons/anomaly/markdown-field_type/input"

Btw: I have the cache cleaned php artisan assets:clear && php artisan view:clear && php artisan route:clear && php artisan cache:clear