Create a new custom field option in redux wordpress framework - wordpress

I want to create new field in redux wordpress framework using Custom fields, but I can't find any help or example using this.
i want to create a field with a switch and text field both.
Any suggestions is most appreciated.

Lead dev of Redux here.
If you want to make a new field, then you should build an extension. We've setup two repos that will help you get started.
First:
https://github.com/ReduxFramework/extension-boilerplate
This is an extension boilerplate. It will help you see how to do this.
Second, is the extension loader:
https://github.com/ReduxFramework/redux-extensions-loader
This will load the extension. You can also use it to overload any existing Redux fields.
Be VERY careful to load your Redux options in this order:
Extension Loader
Redux Options Config File
Otherwise Redux will be initialized before you run the extension hooks to overload/add new types. From there you just call your custom field type like you would any other field.
Good luck!

In order to update the answer, it's important to note that this page refers to the legacy method to load extensions.
The current method to load extensions is by adding the next line into redux config file (I guess is OK to add it at the end of the file).
Redux::setExtensions( 'OPT_NAME', 'FULL PATH' );
...from the docs:
Be sure to replace OPT_NAME with your opt_name and FULL PATH with the full path to your extension(s) location.

Related

How to set template path in redux framework?

I need to customize panel templates in my theme, which I use redux. I copied ReduxCore->templates->panel folder into mythemefolder->redux-framework->ReduxCore->templates->panel.
For some plugins, this overrides the templates from plugin, but not the case here, I found that I need to manually tell redux to look for the templates elsewhere other than default folder inside plugin. but I'm not sure how to do it.
I tried adding 'templates_path' => dirname(__FILE__).'/templates/panel', inside redux config file, but it just throws an error with Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW)
then I found in redux docx,(https://docs.reduxframework.com/core/advanced/filter-hooks/) that there's another way to put redux/{opt_name}/panel/templates_path, but it has no reference how, or where to put this code.
can anyone help me out please?
https://docs.redux.io/guides/advanced/panel-templates.html
Redux::setArgs('opt_name', array('templates_path'=> dirname(__FILE__).'/templates/panel/'));
That SHOULD do it.

Drupal 8 add javascript and pass data in a hook with custom module

I am building a custom module with Drupal 8. One of the requirements of the module is that it sets up a javascript file based on the configuration settings, which the user of the module sets up in module configuration.
The javascript which needs to be added to the page depends on the configuration settings. Hence I can not add it using Libraries as mentioned in this article: Adding assets to Drupal module.
I first implemented it using a block. I use Twig templates to pass the configuration variables in PHP to the twig file, and in the twig file, I have a tag to add the javascript based on the config variables. Refer Using twig templates.
The problem with this approach is that user needs to add the block on the page, and there is no UI facing element on that block. I also find it very messy.
Is there a cleaner way to add my javascript using hook and pass variables to it? I looked around and found hook_install and hook_page_attachments. So I can add Javascript, but don't know how I can pass any php variables to it.
I am new to Drupal development. Any help with this is really appreciated.
TL;DR I need to find a way to add Javascript using Drupal hook and pass some PHP variables to it.
Use in hook_page_attachments:
$attachments['#attached']['drupalSettings']['myvar'] = $myVariable;
Then in your js (I assume you already know how to attach js library):
(function ($, Drupal, drupalSettings) {
Drupal.behaviors.my_custom_behavior = {
attach: function (context, settings) {
var strings = drupalSettings.myvar;
...
}
}
})(jQuery, Drupal, drupalSettings);
See nice Acquia tutorial for more examples.

How does hook_ENTITY_TYPE_create() get invoked?

I've been working with Drupal Console creating custom entity types as well as a custom module which should interface with this entity type. My situation is that I need the hook "hook_ENTITY_TYPE_create()" to be called somehow (I assume it gets called when the entity is created by default).
I guess I must implement this hook in some file, but I'm unsure of which file I should be implementing this hook in.
My module file structure is as follows (generated by Drupal Console)
Thanks
You can put the hook_ENTITY_TYPE_create() in your .module file, but since you noted in your comment that you are trying to react to the saving of the Event entity in your module, you are probably better served by overriding the save() method on the Event entity itself (I believe console gives you a stub method by default).

Using directives in new files

Is it possible to have additional "using" directives automatically added to my new aspx.cs files so that I do not have to keep typing the same ones over and over again (i.e. custom namespace using directives)
You can edit the files that are used by the template. Better yet, create your own. File + Export Template.
You don't have to type them in. When writing the code, type in the name of the class (without the namespace). Then hit CTRL+.. That will open up the resolve type intellisense helper. It will add the using statement to the top of the file. No scrolling necessary.

Drupal6: Removing template files

I have been using a custom template file called user-profile.tpl.php for a while. But wanted to explore the CCK Content Profile abilities.
I renamed the template file to something arbitrary, but instead of drupal defaulting to using the standard profile view it is complaining that it can't find the user-profile.tpl.php file.
So either it saves this in the database somewhere, cache is disabled so that is not the Anyone know how drupal save the template file names? And how that can be reset?
Make sure you flush the theme registry whenever you make a change like that. You can do it using the link in the top left of admin_menu if you're using that module, or if not, go to Settings -> Performance and clear the cache.

Resources