I would like to create a plugin inside a plugin with Cakephp3. I found a solution for Cakephp2 but it doesn't seem to work in Cakephp3:
Is it possible to create a plugin inside a plugin with CakePHP?
How can I do this in Cakephp3?
I'm going to assume your question regards having the plugin loaded in your CakePHP 3.x application, not creating the plugin :-)
Note: this answer assumes you installed Cake using composer.
As an example, let's say we wanted to create a plugin, Themes, and this plugin was going to contain other plugins, Blue and Red.
By convention, the Themes plugin should be contained in your_app/plugins/Themes and the Blue and Red plugins could be contained in your_app/plugins/Themes/plugins/Blue and your_app/plugins/Themes/plugins/Red respectively.
In your_app/config/bootstrap.php , add the following:
Plugin::load('Themes', ['bootstrap' => true]);
(See https://book.cakephp.org/3.0/en/plugins.html#plugin-configuration for info regarding plugin configuration)
The code above tells Cake to load the Themes plugin, and to look for and load the plugin's bootstrap file.
If you haven't already done so, create the Themes plugin's bootstrap file at your_app/plugins/Themes/config/bootstrap.php and have it looking similar to:
<?php
use Cake\Core\Plugin;
// load the red and blue child plugins
Plugin::load('Themes/plugins/Red');
Plugin::load('Themes/plugins/Blue');
Important: Since you're trying to write the plugin(s) manually and not installing via composer, you need to modify your_app/composer.json to contain something like:
"autoload": {
"psr-4": {
"App\\": "src",
"Red\\": "./plugins/Themes/plugins/Red/src",
"Blue\\": "./plugins/Themes/plugins/Blue/src"
}
}
(See https://book.cakephp.org/3.0/en/plugins.html#autoloading-plugin-classes for more info on autoloading plugin classes).
Now, from within your_app/ run:
php composer.phar dumpautoload
(or the equivalent command, depending on how composer was installed on your machine)
This tells composer to refresh its autoloading cache. If you were to inspect your_app/vendor/cakephp-plugins.php, you should see that a path to the Themes plugin's folder has been added to a pre-existing list of plugin paths.
Now, from within your app's main controllers, you should be able to have stuff like:
public function initialize()
{
// load (supposedly-existing) components from the "Red" or "Blue" themes
// load GradientComponent of the "Red" theme
$this->loadComponent('Red.Gradient');
// load ColorComponent of the "Blue" theme
$this->loadComponent('Blue.Color');
// use what you asked for...
$this->Color->someMethod(['data']);
parent::initialize();
}
Also, to use view files (that you'd expect theme plugins to provide :-) ):
public function beforeRender(Event $event)
{
// use the "home" layout from the Red theme
$this->viewBuilder()->setLayout('Themes/plugins/Red.home');
parent::beforeRender($event);
}
Related
I might be asking the wrong question (I'm not a coder), but I'm attempting to paste HTML and the inline stylesheet into the text-side (HTML-side) of the Wordpress Visual Composer to create an email layout, and the finished product of that is the entire stylesheet written out above the un-styled HTML layout, so I'm assuming inline stylesheets are not supported in this composer.
Some back story for clarity, I'm using the plugin 'Download After Email' which only provides the standard Wordpress visual composer in order to create the email a user receives once they 'sign up'. This seemingly limits me to either jazzing up some text a little bit like I was using Microsoft Word (which isn't sufficient for a brand-focused business), or using raw standalone HTML, which isn't really sufficient for a properly formatted template.
Are there any plugins which may assist in adding CSS styling here that will work once it's displayed externally to the website, i.e. in an email browser?
Judging by the image, you have a regular editor but not Visual Composer, and this is very good because this is the only right direction! You cannot create email templates using the constructor (Visual Composer) since creating an email template requires special old school knowledge (Tables, inline styles) and clean markup. I advise you to take a ready-made template and change it to your own.
Example: https://colorlib.com/etc/email-template/3/index.html
What you need to know:
You need to use html tables
You need to use inline css
Use full src to display images (https://yoursite.wp/.../demo.jpg) the link you can get from the media post
Not recommended:
To use css styles in the header if you are interested in Gmail App support:
https://templates.mailchimp.com/resources/email-client-css-support/
Custom fonts
Visual Composer and any other constructor
Addition:
If you can use the shortcode system I recommend creating a mini plugin for you:
plugins/my-custom-emails [Root directory of new plugin]
plugins/my-custom-emails/my-custom-emails.php [Main php file of plugin]
plugins/my-custom-emails/emails/ [Directory for for all your templates]
plugins/my-custom-emails/emails/template1.html [First demo template]
my-custom-emails.php
<?php
/*
Plugin Name: My emails
Description: My custom emails
Version: 0.1.0
*/
define('MYCELS_DIR', plugin_dir_path(__FILE__));
add_shortcode( 'myemails', 'MYCELS_SHORTCODE' );
function MYCELS_SHORTCODE($attrs) {
if(empty($attrs['id'])) {
return 'ID required';
}
$ID = $attrs['id'];
$PATH = MYCELS_DIR . 'emails/'.$ID.'.html';
if(file_exists($PATH)) {
return file_get_contents($PATH);
} else {
return 'File with '. $ID . ' ID not exists';
}
}
template1.html
<div>
Template
</div>
And using:
[myemails id=template1]
Id = template name
If you want something very customisable this plug-in would work,
https://en-gb.wordpress.org/plugins/wp-html-mail/
It’s very good and would recommend!
With this you have full control over CSS and the HTML also comes with templates and has so much more control for what you need!
I'm developing a module where I've some custom js functions to be use in a form inside a Dialog.
I successfully loaded as inline script in the view that launch the dialog that include the form with something like:
$script = <<< JS
var scheda=$("table#schedaTable");
var idtum=scheda.attr('idtum');
scheda.find("i.modifica.concessione").on('click', function() {
$("#concessioneDialog").load("/cimiteriale/concessioni/edit-concessione?idtum="+idtum).dialog("open");
});
JS;
$this->registerJs($script, $this::POS_END);
but for several reasons I prefer to use an external file published in assets so my question is:
Is it possible to publish an external js file with MyModuleAssets.php and register it later in the view independently from the other js assets, where needed?
In fact I need to close and reopen the dialog with other ids and so I need to register the js again several time.
Could someone give me an hint and maybe some pieces of the core code?
Thanks in advance
Luca
Assets are published as a package. So if you want some JS/CSS to be registered somewhere and others in another situations, you should create different packages and register each of them when needed.
I was wondering how do you add link tag/google font to head in yii2.
I want to add the following
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700' rel='stylesheet' type='text/css'>
I have found this documentation but doesn't mention anything about link/adding google font etc
The correct answer is to create a new AssetBundle.
While you can directly place the HTML for the fonts into the of your main.php file, this isn't the Yii way. If you have tried to load jQuery files this way, you might notice odd behavior when directly putting them into the HTML.
For example: Directly place the HTML tag for Bootstrap CDN into the head of your main.php. Then, somewhere in your code try to use the tooltip. You will get an error in your console that tooltip is not a function. - This is because the way Yii puts all your template files together, and at that time, Bootstrap is not available.
While simply loading a font probably won't cause any problems, it is a good idea to do things the way they were intended. Following MVC rules, properly documenting your code, and following the Yii best practices, will go a long way. Not only will you thank yourself a year later when you have to go back into a project, but the next guy will appreciate it. I can't stand going into systems, and seeing stuff thrown everywhere, chincy hacks, and spaghetti code, and no documentation or comments.
Correct Way:
Create a new AssetBundle. In your assets folder, you probably already have AppAsset.php. Duplicate it, and name it FontAsset.php.
Here is an example from my project, using 3 Google fonts.
FontAsset.php
<?php
namespace app\assets;
use yii\web\AssetBundle;
class FontAsset extends AssetBundle
{
public $basePath = '#webroot';
public $baseUrl = '#web';
public $css = [
'//fonts.googleapis.com/css?family=Open+Sans:400,700',
'//fonts.googleapis.com/css?family=Ubuntu:400,700',
'//fonts.googleapis.com/css?family=Oswald:400,700'
];
public $cssOptions = [
'type' => 'text/css',
];
}
In your layout, main.php for example. Right under where you see AppAsset::register($this)
main.php
use app\assets\FontAsset;
FontAsset::register($this);
For every layout file that you want to load those fonts, include the FontAsset.
The AssetBundle is basically a bundle of CSS and/or JS files and options. You could add another one for say JWPlayer say named VideoAsset, and add your JS/CSS files for JWPlayer in it.
Point being, you shouldn't be adding these things directly into the HTML of the layouts directly, as it can cause problems. Let the AssetManager handle them by declaring AssetBundles.
It might save you later down the road!
The best way is to create an asset bundle and add the link to the bundle.
You can find a complete guide here:
http://www.yiiframework.com/doc-2.0/guide-structure-assets.html
You can put it directly in the head of the layout (file views/layouts/main.php)
I am trying to get a custom css file to load after the plugin stylesheets. I was thinking I could use the $deps parameter of wp_register_style(), but the css file does not load at all when I add the array(). This happens no matter what is included in the $deps array(), ie (array('style')
, array('style.css')).
Is there an issue with the call, or a better way of doing this?
In my functions.php
// Load custom css
add_action('wp_enqueue_scripts', 'prefix_add_my_stylesheet');
function prefix_add_my_stylesheet() {
wp_register_style( 'custom-supersized-styles', get_template_directory_uri(). '/css/custom-supersized-styles.css', array('style','supersized');
wp_enqueue_style( 'custom-supersized-styles' );
}
If you're using the WP Supersized plugin try registering your function like so:
// Load custom css
add_action('wp_enqueue_scripts', 'prefix_add_my_stylesheet', 999);
The dependencies array (the parameter you're attempting to use to add supersized with) depends on supersized having already been registered by WordPress. If you set the priority of your own prefix_add_my_stylesheet to a higher number, it should then load after the plugin has registered and loaded its CSS (and thus will be available).
In addition, you can remove the style as a dependency. (style is never registered by WordPress as a dependency handler, and your enqueued scripts / css should be loading after style.css loads anyway).
Hope that helps!
I want to wrap a mediawiki site inside another site - using the header.inc and footer.inc files that the rest of the website's html files use.
I'm not familiar with php, is there a 'masterpage' file somewhere I can put them in?
Your best bet would be to create a custom skin, or edit one of the default skins, such as monobook. They control most of the basic presentation code. Here is one short tutorial on creating a custom skin. The files usually live in the /skins/ folder; if you skim through one, you can find where the HTML begins and ends.
You can include another file using the PHP include function, like so:
<html>
...
<body>
<?php
include 'header.inc';
?>
...
For future reference in the LocalSettings.php you can also prevent users from using any other skin.
$wgDefaultSkin = 'myskin';
$wgAllowUserSkin = false;
$wgSkipSkins = array( "chick", "cologneblue", "monobook", "modern", "myskin", "nostalgia", "simple", "standard" );