How to Override xxx_xxx_Create method?
Hay., i'am newbie here and want ask question.
I'am trying make custom theme and need to override this method for custom pagination.
// file in applications/vanilla/settings/class.hooks.php
public function profileController_Comments_Create($Sender, $UserReference = '', $Username = '', $Page = '', $UserID = '') {
// the content
}
I try place it in class theme hooks, not working.,
I try change _Create to _Override, not override.,
Please help, thanks.
Best Answers
-
Bleistivt Moderator
Afaik _create methods cannot be overriden.
But you can make the route point to a new method:
public function gdn_dispatcher_appStartup_handler($sender) { Gdn::router()->setRoute('^profile/comments(/.*)?', 'profile/newcomments$1', 'Internal', false); } public function profileController_newComments_create($Sender, $UserReference = '', $Username = '', $Page = '', $UserID = '') { // ... }
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
6 -
R_J Admin
You do not have to rewrite a form control that already exists. You just need to use "radioList()".
Copying complete views and making small changes to them is a bad habit. If you like small modifications, you should do them by changing only the pieces that you do not like. If you look at the view that you try to change, you see that the category selector is only shown if a flag is set
ShowCategorySelector
. By setting this to false, you can prevent that it will be rendered.If the default category dropdown isn't shown, you can render your own form element. And, as I've said before, radioList() already exists:
public function postController_beforeFormInputs_handler($sender, $args) { // This prevents the default category drop down from bein rendered. $sender->ShowCategorySelector = false; // Get all the categories the user is allowed to see. $categories = CategoryModel::getByPermission(); // Reduce information to [ID => Name] $categories = array_column($categories, 'Name', 'CategoryID'); // Create a radio list. echo '<div class="P">'; echo '<div class="Category">'; echo $sender->Form->label('Category', 'CategoryID'); echo $sender->Form->radioList('CategoryID', $categories); echo '</div>'; echo '</div>'; }
That's all you need (and a little bit of styling)
3
Answers
Afaik _create methods cannot be overriden.
But you can make the route point to a new method:
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
This a URL redirect?
No, this happens internally. It will be just like if the method was overridden.
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
Thanks, your solution work perfectly. But, what happen if i change "'Internal', false" to "'Internal', true", and what this.
if you change the last parameter, it will persist even after you disable the plugin, because it gets saved to the config.php
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
One more question in this section, hope you can help.
I'am change select option category in post page to radio button. Working perfect with add new form function in library/core/class.form.php , but i think it not true method.
This for example:
public function categoryDropDown($FieldName = 'CategoryID', $Options = false) {
//...
}
I'am add new function below:
public function categoryDropDownXxx($FieldName = 'CategoryID', $Options = false) {
//...
}
My question,
How to place public function categoryDropDownXxx to theme or plugins? I try add it in class hooks theme and to plugins, but error.
If you really need to use your own function here put it in a plugin, and override the the post view.
But I would do this with jQuery since it is just a cosmetic change:
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
How to make it, "override the the post view", can you help me?
Solution with jQuery, for me not recomended.
copy
applications/vanilla/views/post/discussion.php
tothemes/YOURTHEME/views/post/discussion.php
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
I already doing it since start custom themes.
I looking method to override or make new GDN_Form from class.form.php, so i not change core code.
I need to override / change this with my own:
echo $this->Form->CategoryDropDown('CategoryID', array('Value' => val('CategoryID', $this->Category), 'IncludeNull' => TRUE));
to this,
echo $this->Form->CategoryDropDownMyOwn('CategoryID', array('Value' => val('CategoryID', $this->Category), 'IncludeNull' => TRUE));
Well, you can always create a subclass that extends Gdn_Form and overwrite the factory:
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
Okay, now i will start to explain with more detail.
I create custom theme and all views already copy to theme for override.
Now, in file class.form.php i create new function. This the code:
And I modified select option category to radio button /ThemeName/views/post/discussion.php, change this
echo $this->Form->CategoryDropDown('CategoryID', array('Value' => val('CategoryID', $this->Category), 'IncludeNull' => TRUE));
to this
echo $this->Form->CategoryDropDownOpsional('CategoryID', array('Value' => val('CategoryID', $this->Category), 'IncludeNull' => TRUE));
My question, how to place
public function categoryDropDownOpsional($FieldName = 'CategoryID', $Options = false) {
//conten
}
to plugins / theme hooks.
You do not have to rewrite a form control that already exists. You just need to use "radioList()".
Copying complete views and making small changes to them is a bad habit. If you like small modifications, you should do them by changing only the pieces that you do not like. If you look at the view that you try to change, you see that the category selector is only shown if a flag is set
ShowCategorySelector
. By setting this to false, you can prevent that it will be rendered.If the default category dropdown isn't shown, you can render your own form element. And, as I've said before, radioList() already exists:
That's all you need (and a little bit of styling)
thanks @R_J , you'r solution give me inspitration.