How to override field_type view?
Created 2 years ago by oimkenIs 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.
Is it set as active? Ill give it a test on my end but I've just recently done this very thing.
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.
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.
Try this: https://pyrocms.com/help/developer-tools/extending-pyrocms/overriding-views
Manually Registering Overrides
BadMethodCallException
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:
$overrides->put(
'anomaly.field_type.markdown',
[
'anomaly.field_type.markdown::input',
'oimken.theme.simple::addons/anomaly/markdown-field_type/input',
]
);
Not working.
No use add - and make sure you're up to date. PUT is a mass add.
https://github.com/anomalylabs/streams-platform/blob/1.3/src/View/ViewOverrides.php#L22
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
Hmm that looks right. You can also place a view in your theme views like
addons/anomaly/markdown-field_type/input.twig
: https://pyrocms.com/help/developer-tools/extending-pyrocms/overriding-views