Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

Commit

Permalink
feat(Components/BlockWysiwyg): add component (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
usingthesystem authored and Doğa Gürdal committed May 11, 2017
1 parent 650837a commit 9d08f57
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Components/BlockWysiwyg/fields.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"layout": {
"name": "blockWysiwyg",
"label": "Block: Wysiwyg",
"sub_fields": [
{
"name": "contentHtml",
"label": "Content",
"type": "wysiwyg",
"delay": 1,
"media_upload": 0,
"toolbar": "full",
"required": 1
}
]
}
}
9 changes: 9 additions & 0 deletions Components/BlockWysiwyg/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Flynt\Components\BlockWysiwyg;

use Flynt\Features\Components\Component;

add_action('wp_enqueue_scripts', function () {
Component::enqueueAssets('BlockWysiwyg');
});
164 changes: 164 additions & 0 deletions Components/BlockWysiwyg/howto.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Developer HowTo´s

### Editor Toolbar

The MCE Buttons that show up by default are specified in the **TinyMce Feature**, in the `mce_buttons` filter.

You can either modify that Feature to modify all the wysiwyg toolbars globally (all over your project), or define a specific configuration for one specific wysiwyg field, by using the `acf/fields/wysiwyg/toolbars` acf filter on your `functions.php` file.

#### To change the Toolbar globally on every TinyMce
Go to the [TinyMce Feature](../../Features/TinyMce/README.md).

#### To define a specific configuration for one specific Wysiwyg field
Go to the component (`Wysiwyg` here) `functions.php` file, and use the `acf/fields/wysiwyg/toolbars` acf filter:

```php
<?php
add_filter('acf/fields/wysiwyg/toolbars', function ($toolbars) {
$toolbars['myCustomToolbar'] = [];
$toolbars['myCustomToolbar'][1] = [
'formatselect',
'styleselect',
'bold',
'italic',
'underline',
'strikethrough',
'|',
'bullist',
'numlist',
'|',
'outdent',
'indent',
'blockquote',
'hr',
'|',
'alignleft',
'aligncenter',
'alignright',
'alignjustify',
'|',
'link',
'unlink',
'|',
'forecolor',
'wp_more',
'charmap',
'spellchecker',
'pastetext',
'removeformat',
'|',
'undo',
'redo',
'wp_help',
'fullscreen',
'wp_adv', // toogle second bar button
];
return $toolbars;
});
```

In this example, we create a new toolbar called `myCustomToolbar`. You define which buttons show up. Then you need to specify that toolbar on your Wysiwyg field configuration (fields.json):

```json
{
"name": "contentHTML",
"label": "Content",
"type": "wysiwyg",
"media_upload": 0,
"required": 1,
"toolbar": "myCustomToolbar"
}
```

### Editor Styles

You can also create new **styles**, globally by modifying the [TinyMce Feature](../../Features/TinyMce/README.md).

Unfortunately there is no way to have a stylesheet to a specific acf Wysiwyg field as it is possible for toolbars. So your stylesheet will be applied to all TinyMce instances.


## Snippets
### Default Theme

`fields.json`
```json
{
"layout": {
"name": "blockWysiwyg",
"label": "Block Wysiwyg",
"sub_fields": [
{
"name": "settingsTab",
"label": "Settings",
"type": "tab"
},
{
"name": "theme",
"label": "Theme",
"type": "select",
"choices": {
"": "---",
"wysiwyg-fullwidth": "Fullwidth",
"wysiwyg-narrow": "Narrow"
},
"default_value": ""
}
]
}
}
```

`index.twig`
```html
<div class="blockWysiwyg {{ theme }}"></div>
```

`style.styl`
```stylus
$containerMaxWidth = lookup('$global-layout-containerMaxWidth') || 1140px
$narrowWidth = lookup('$global-layout-narrowWidth') || 650px
[is='flynt-block-wysiwyg']
.blockWysiwyg
center($containerMaxWidth, $gutterWidth)
&-fullwidth
center($containerMaxWidth, $gutterWidth)
&-narrow
center($narrowWidth, $gutterWidth)
```

## Additional Global Default Theme

To add an additional Global Default Theme simply add the following code to the Default Theme solution from above.

`fields.json`
```json
{
"options": [
{
"name": "defaultTheme",
"label": "Default Theme",
"type": "select",
"choices": {
"": "---",
"wysiwyg-fullwidth": "Fullwidth",
"wysiwyg-narrow": "Narrow"
},
"default_value": ""
}
]
}
```

`functions.php`
```php
<?php
add_filter('Flynt/addComponentData?name=BlockWysiwyg', function ($data) {
if (empty($data['theme'])) {
$data['theme'] = get_field('defaultTheme', 'options');
}
return $data;
});
```
5 changes: 5 additions & 0 deletions Components/BlockWysiwyg/index.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div is="flynt-block-wysiwyg" class="flyntComponent">
<div class="blockWysiwyg">
{{ contentHtml }}
</div>
</div>
13 changes: 13 additions & 0 deletions Components/BlockWysiwyg/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Title: Block Wysiwyg

----

Category: Block

----

Tags: wysiwyg, content, html, dom

----

Text: Content Editor.
13 changes: 13 additions & 0 deletions Components/BlockWysiwyg/style.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$rupture.scale = lookup('$global-layout-scale') || (0 576px 768px 992px 1200px)
$rupture.anti-overlap = lookup('$global-layout-overlap') || -1px
$gutterWidth = lookup('$global-layout-gutterWidth') || 15px
$containerMaxWidth = lookup('$global-layout-containerMaxWidth') || 1140px

[is='flynt-block-wysiwyg']
*,
*:before,
*:after
box-sizing: border-box

.blockWysiwyg
center($containerMaxWidth, $gutterWidth)
4 changes: 3 additions & 1 deletion config/fieldGroups/pageComponents.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"label": "Page Components",
"type": "flexible_content",
"button_label": "Add Component",
"layouts": []
"layouts": [
"Flynt/Components/BlockWysiwyg/Fields/Layout"
]
}
],
"location": [
Expand Down

0 comments on commit 9d08f57

Please sign in to comment.