We have a boilerplate module that we include on all of your SilverStripe builds. We are attempting to add a new class to our customised WYSIWYG config.
The weird thing is that we have a module dedicated to this but as soon as we move this configuration out of that module and into the new module, the config reflects only a couple of the changes and not all.
Example:
wysiwygboilerplate/_config.php
companyname-boilerplate/_config.php
The first example shows the correct wysiwyg configuration. When that same code is moved to the new location 'companyname-boilerplate/' directory it ceases to function.
This is the snippet of code I am working with. (with the only update being the path to content css)
//-------------------------------------------- WYSIWYG config
$defaultEditorConfig = HtmlEditorConfig::get('cms');
$defaultEditorConfig->setOptions(
array(
'theme' => 'advanced',
'priority' => 1,
'browser_spellcheck' => true,
'body_class' => 'wysiwyg',
'content_css' => '/companyname-boilerplate/styles/wysiwyg.css',
'schema' => 'html5',
'extended_valid_elements' => 'figure,figcaption',
'end_container_on_empty_block' => true,
'style_formats' => array(
array(
'title' => 'H1',
'block' => 'h1'
),
array(
'title' => 'H2',
'block' => 'h2'
),
array(
'title' => 'H3',
'block' => 'h3'
),
array(
'title' => 'H4',
'block' => 'h4'
),
array(
'title' => 'H5',
'block' => 'h5'
),
array(
'title' => 'Paragraph',
'block' => 'p'
),
array(
'title' => 'Blockquote',
'block' => 'blockquote',
'wrapper' => true
),
array(
'title' => 'Figure',
'block' => 'figure',
'wrapper' => true
),
array(
'title' => 'Figure caption',
'block' => 'figcaption',
'wrapper' => true
)
)
)
);
$defaultEditorConfig->disablePlugins('contextmenu');
$defaultEditorConfig->enablePlugins('lists', 'paste');
$defaultEditorConfig->setButtonsForLine(1, 'styleselect, formatselect, separator, bold, italic, separator, justifyleft, justifycenter, justifyright, separator, bullist, numlist, separator, charmap, ssmedia, separator, sslink, unlink, separator, code');
$defaultEditorConfig->setButtonsForLine(2);
$defaultEditorConfig->setButtonsForLine(3);
My initial thoughts are that this is to do with the order SilverStripe is loading the configuration files, but there are no other files / modules that define a HtmlEditorConfig that I am aware of.
The other thought I had was around caching, I cleared out the SilverStripe cache, my browser cache and even ran a dev/build with still no joy, so that rules out caching
As the modules config are included in alphabetical order you either have to rename your boilerplate module (or the installation dir in composer.json) that it comes after framework or put the config inside mysite manually, cause mysite is added at last and there you can overwrite settings.
Related
I'm working on a WP Theme that uses Redux Framework and I am trying to create a filter for fields that have a URL attached to them, ie, Background Fields, Media Fields, so that I can make them Protocol relative and able to use SSL site-wide without conflicts.
So far I have the following function in my options-init.php file for a Background Field but to be honest I have very little experience with Filters, and the documentation for Redux Framework is very vague.
Field is as follows:
array(
'id' => 'front-background',
'type' => 'background',
'url' => true,
'title' => __('Front Page Background', 'blanque'),
'desc' => __('Background image for Front Page', 'blanque'),
'subtitle' => __('', 'blanque'),
'compiler' => true,
'output' => array(
'background' => 'body.home',
),
'default' => array(
'url' => '',
),
'background-color' => false,
'preview_height' => '100px',
)
Fuction to filter output:
function the_theme_redux_filters($url) {
$relativeURL = str_replace(array('http://','https://'), '//', $url);
return $relativeURL;
}
add_filter( 'redux/validate/front-background/class/{field.validate}', '', 10, 1 );
Would someone be able to give me a clue as to what I should actually be doing please?
In my web application I use tabs and load part of the views per Ajax. So it's possible, that I do load the same CGridView multiple times without reloading the page. If that occurs I become duplicate Ajax requests if I use CGridView Filters.
The filters and requests are standard. Following images show those simple filter and 10 GET requests if type the search value once.
Here is the code of Tabs-widget I use:
$this->widget('bootstrap.widgets.TbTabs', array(
'id' => 'thirdPartyCatTabs',
'title' => Translate::t('project', 'Categories'),
'type' => 'tabs',
'placement' => 'top',
'events' => array(
'shown' => 'js:loadContent'
),
'tabs' => array(
array(
'id' => 'standardCat',
'label' => Translate::t('project', 'Standard Categories'),
'linkOptions' => array(
'data-tab-url' => Yii::app()->createUrl('/thirdParty/settings/thirdPartyCategoryStandard'),
),
),
array(
'id' => 'standardCatMap',
'label' => Translate::t('project', 'Standard Category-Mapping'),
'linkOptions' => array(
'data-tab-url' => Yii::app()->createUrl('/thirdParty/settings/showCategoryMapTab'),
),
),
)
));
I guess I have to use uniqid() at some place, but can't figure out where.
Thanks.
I'm new to Drupal and I'm looking for a way to add a new field to an already installed content-type in Drupal 7. Please note that some content is already present in the database. Also, I need to do this programmatically and not via a GUI.
Googling, I have already found the following documents, which seem to be related:
https://api.drupal.org/api/drupal/modules!field!field.module/group/field/7
https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_update_N/7
Still, my ideas are a bit confused and a basic example would clarify things.
This snippet should get you started. It was found on the Drupal Stackexchange. I suggest you check there first in the future.
https://drupal.stackexchange.com/questions/8284/programmatically-create-fields-in-drupal-7
$myField_name = "my_new_field_name";
if(!field_info_field($myField_name)) // check if the field already exists.
{
$field = array(
'field_name' => $myField_name,
'type' => 'image',
);
field_create_field($field);
$field_instance = array(
'field_name' => $myField_name,
'entity_type' => 'node',
'bundle' => 'CONTENT_TYPE_NAME',
'label' => t('Select an image'),
'description' => t(''),
'widget' => array(
'type' => 'image_image',
'weight' => 10,
),
'formatter' => array(
'label' => t('label'),
'format' => 'image'
),
'settings' => array(
'file_directory' => 'photos', // save inside "public://photos"
'max_filesize' => '4M',
'preview_image_style' => 'thumbnail',
'title_field' => TRUE,
'alt_field' => FALSE,
)
);
field_create_instance($field_instance);
drupal_set_message("Field created successfully!");
}
You can execute this code countless ways. I am not privy to the requirements of your project so its hard for me to make a recommendation. You could hook this into the update/install functions, or you could build it into a page hook in a module, or you could just bootstrap any new php file in the root directory with this:
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
Running into a bit of a hurdle, and I can't find any supporting documentation. My use case is fairly simple. The Application module has javascript that should go into the head, and one of my other modules, Foo also has script that should go into the head. I assumed that this Assetic module could solve that. Here's what I inferred:
Application Config
/**
* Assetic
*/
'assetic_configuration' => array(
'buildOnRequest' => true,
'cacheEnabled' => false,
'webPath' => realpath('public/assets'),
'basePath' => 'assets',
'default' => array(
'assets' => array(
'#base_css',
'#head_js',
),
'options' => array(
'mixin' => true,
),
),
'modules' => array(
'application' => array(
# module root path for yout css and js files
'root_path' => __DIR__ . '/../assets',
# collection of assets
'collections' => array(
'base_css' => array(
'assets' => array(
'css/*.css',
),
'filters' => array(),
'options' => array(),
),
'head_js' => array(
'assets' => array(
'js/*.js',
),
'filters' => array(),
),
'base_images' => array(
'assets'=> array(
'images/*.png',
),
'options' => array(
'move_raw' => true,
)
),
),
),
),
),
and then in my Foo module...
Foo Module config
/**
* Assetic
*/
'assetic_configuration' => array(
'default' => array(
'assets' => array(
'#base_css',
'#head_js',
),
'options' => array(
'mixin' => true,
),
),
'modules' => array(
'foo' => array(
# module root path for yout css and js files
'root_path' => __DIR__ . '/../assets',
# collection of assets
'collections' => array(
'base_css' => array(
'assets' => array(
'css/*.css'
),
'filters' => array(),
'options' => array(),
),
'head_js' => array(
'assets' => array(
'js/*.js' // relative to 'root_path'
),
'filters' => array(),
'options' => array(),
),
'base_images' => array(
'assets'=> array(
'images/*.png'
),
'options' => array(
'move_raw' => true,
)
),
),
),
),
),
With this config, unfortunately, only the Foo module's javascript makes its way into head_js.js. I'm feeling like that meme with Milton in it, going "I was told there would be asset combining!" :)
Any help you could offer, is appreciated.
Thanks!
Ok - I've figured it out. Hopefully this helps someone else one day. The configuration keys I noted above weren't inaccurate -- but -- they weren't crafted properly when a secret undocumented feature is considered; had to crack the source open to learn that including the word 'head' in an asset bundle actually autoloads it in the head. It's a nice feature in the end, but really a head scratcher when you're not aware of it.
I'm trying to use AssetManager module with Zend Framework 2.
I have a problem with using filter. At the moment I can combine css files with following (in module.config.php):
'resolver_configs' => array(
'collections' => array(
'css/combined.css' => array(
'css/a.css',
'css/b.css'
),
'paths' => array(
__DIR__ . '/../public'
),
),
),
The problem is I cannot minify a css file with following:
'filters' => array(
'css/combined.css' => array(
array(
'filter' => 'UglifyCss'
),
),
),
I have also tried CssMin filter, but it doesn't minify either.
There is the documentation about filter, and the filter does not work out of the box and it needs to provide dependencies. If the filters like UglifyCss and CssMin need dependencies, then how do I know what dependencies are needed and how do I provide them?
The filters don't work on collections. They can only be applied to individual assets. If you wish to minify a stylesheet collection you'll have to minify the individual components inside of the collection.
Considering the following configuration:
'resolver_configs' => array(
'collections' => array(
'css/combined.css' => array(
'css/a.css',
'css/b.css'
),
'paths' => array(
__DIR__ . '/../public'
),
),
),
You'll need these filters:
'filters' => array(
'css/a.css' => array(
array(
'filter' => 'UglifyCss'
),
),
'css/b.css' => array(
array(
'filter' => 'UglifyCss'
),
),
),
As to supplying the dependencies for filters, you can look inside of the filters themselves. They usually contain a link to the required file(s): https://github.com/kriswallsmith/assetic/blob/master/src/Assetic/Filter/JSMinFilter.php#L21