How to access "required" value in view file using Kohana Formo - kohana

I have a following code initializing Formo
$form = Formo::form();
$form->add('field', 'input', 'default', array('required'=>true));
How do I access the "required" value inside the view file?

From the Form Docs:
$required = $field->view()->attr('required');

Related

JQuery FileDrop.js How To Read Data Params in Controller?

Using ASP.NET MVC 5, I'm having trouble reading the param data I am sending from my filedrop jquery code into my controller.
Here is my .cshtml filedrop code:
And here is my Controller code, showing that param1 is being passed as null:
You can try defining a variable that will hold that the value of attribute. like this
var idValue = $('id').val();
And then pass this variable to the data.
data: { params: idValue }

Drupal 8 Custom module - how to create a field in the admin area, and then pull that input in my module to use?

New to Drupal 8, I'm coming from the WP world so it's been very confusing getting the hang of things. I created a custom module and have a page outputting text. Where I'm stuck is the ability to make a field in the admin area, pull that saved info, and then use it in my content that's being output.
Been following along with tutorial but am very stuck. Can anyone provide a road map for me or helpful articles to accomplish this?
Suppose your module name is "custom" then follow these steps to create a admin form and pull the saved info on admin page.
Create a folder name "custom".
Create "custom.info.yml" file within "custom" folder.
name: custom
description: Show admin saved data through custom module.
type: module
# core: 8.x
configure: admin/config/services/custom
Create a Permission for who access admin form.
For Permission create "custom.permissions.yml" file within "custom" folder.
'administer custom':
'title': 'Administer Customform'
'description': 'Configure how Custom Form is used on the site.'
restrict access: true
Then create a route for custom admin form path & it's content.
Create "custom.routing.yml" file within "custom" folder.
custom.config:
path: '/admin/config/custom/config'
defaults:
_form: '\Drupal\custom\Form\CustomConfigForm'
_title: 'Custom Configuration'
requirements:
_permission: 'administer custom'
Now create a menu and assign this route ("custom.config") in menu path & create a form within custom folder and the form location is
src/Form/CustomConfigForm.php
For menu create a "custom.links.menu.yml" file within "custom" folder.
custom.config:
title: 'Custom '
description: 'Custom Admin Configuration'
parent: system.admin_config
route_name: custom.config
weight: 100
For admin form create CustomConfigForm.php file within custom folder and the file location is src/Form/CustomConfigForm.php
<?php
namespace Drupal\custom\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class CustomConfigForm extends ConfigFormBase {
public function getFormId() {
return 'custom_config_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('custom.settings'); // store data in custom.settings
$form = parent::buildForm($form, $form_state);
$form['custom_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Content Types'),
'#description' => t('Configure where the custom button should appear.'),
'#options' => node_type_get_names(),
'#default_value' => $config->get('custom_types', array()),
);
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('custom.settings');
$config->set('custom_types', $form_state->getValue('custom_types'));
$config->save(); // save data in custom.settings
return parent::submitForm($form, $form_state);
}
public function getEditableConfigNames() {
return ['custom.settings'];
}
}
Now when you save admin form then after you fetch the saved data in "custom.module" file to use this code.
Create "custom.module" file within custom folder.
$config = \Drupal::config('custom.settings'); // get saved settings
$types = $config->get('custom_types', array()); // fetch particular saved data "custom_types"
print $types;
Now enable this module.
Your admin form path is YOUR_SITE_NAME/admin/config/custom/config
Also in Drupal 8 sometimes cache problem occurs, so if any problem comes then clear the cache after form save.

How to override template file item-list.html.twig for field_slider_images in Drupal 8?

I want to override the item listing template file core/themes/classy/templates/dataset/item-list.html.twig for listing the fields field_slider_images as well as field_blog_tags respectively of their's multiple values of the field.
I have selected "Unordered List" in the view.
Please do check the attached image.
I have created following files :
item-list--field-blog-tags.html.twig
item-list--field-slider-images.html.twig
But, this is not rendered for the listing of the fields.
When I have created item-list.html.twig then only it will access.
However, both fields have different data to style and I am not able to get the current field name which is loading it's data in item-list.html.twig.
Had a brief look at this and it doesn't seem that 'item-list' to have suggestions, which is quite unfortunate.
In this situation there are two options:
Create your own suggestion which would accomplish exactly what you need.
You'll have to do something like this:
/
/*add new variable to theme with suggestion name*/
function hook_theme_registry_alter(&$theme_registry) {
$theme_registry['item_list']['variables']['suggestion'] = '';
}
//send a value to newly added variable to use it build the suggestion
function hook_ENTITY_TYPE_view(array &$build, $entity, $display, $view_mode) {
//add condition here if field exists or whatever, do the same for other field
$build['field_slider_images']['#suggestion'] = 'field_slider_images';
}
//use newly added variable to build suggestion
function hook_theme_suggestions_THEME_HOOK(array $variables) {//THEME_HOOK=item_list
$suggestions = array();
if(isset($variables['suggestion'])){
$suggestions[] = 'item_list__' . $variables['suggestion'];
}
return $suggestions;
}
Now you should be able to use item-list--field-slider-images.html.twig
Second option is to do what others in core did: use a new theme
function hook_ENTITY_TYPE_view(array &$build, $entity, $display, $view_mode) {
//add condition here if field exists or whatever, do the same for other field
$build['field_slider_images']['#theme'] = array(
'item_list',
'item_list__field_slider_images',
);
}

Kentico CKEditor Configure Style Set Dynamically

I'm using Kentico 9 and I'd like to be able to use different CK Editor style sets on different pages. I have added a style set to the styles.js file as follows.
CKEDITOR.stylesSet.add("mystyles", [{ name: "testone", element: "p" }]);
Then in the page I've added some JS as per the CK Editor web site.
if (CKEDITOR.currentInstance) {
CKEDITOR.currentInstance.config.stylesSet = "mystyles";
}
When I load the page containing the CK Editor, the style drop down contains the default style set, not the custom one I defined.
Does anyone know how to achieve this?
If I remember it right you need to define your new toolbarset in config.js (CMSAdminControls/CKEditor/config.js) dropdown.
Something like:
config.toolbar_Basic = [
['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'InsertLink', 'Unlink']
];
The other thing - you need to add new option to this dropdown in Webparts application > EditableText webpart> Properties > HTMLAreaToolbar > DataSource
Here's the documentation you need to read.
The dropdown styles are defined in CMS\CMSAdminControls\CKeditor\styles.js, such as:
{ name: 'Italic Title', element: 'h2', styles: { 'font-style': 'italic' } },
You define the name of the style (the name appears in the dropdown), and then the element and style(s) that should be applied.
After editing the file, make sure you clear your browser cache.
As most Kentico admin interface pages are nested and iframe'd, the caching is pretty agressive, and your styles might not appear until cache is cleared.
Well, it's just javascript after all, so you can simply check the url in some if statement or in some switch-case and then apply styles you need. Do you need some code example? You should be able to find many of them on the internet :)
Here is how I solved my issue. I added the following to styles.js:
CKEDITOR.stylesSet.add("my-styles", [
{ name: "Paragraph", element: "p" },
{ name: "Heading 1", element: "h1" }
]);
Then, in the master page for the area of my site that needs to use the "my-styles" style set, I added:
<script>window.ckstyleset = "my-styles"</script>
Finally, in config.js I added:
var styleset = window.ckstyleset ? window.ckstyleset : "default";
config.stylesSet = styleset;
Using this approach I was able to customise the styles listed in the drop down depending on what master page was is use.

Trying to call a method from a bean within my custom control

This code is in the beforePageLoadEvent of an xPage:
var aURL = eStarService.fetchDocLibraryDocumentURL( sessionScope.get( "PropertyNo" ), "Budget" );
sessionScope.put( "docURL",aURL );
var docUNID = eStarService.fetchDocLibraryDocumentUNID( sessionScope.get( "PropertyNo" ), "Architectural Change Form" );
sessionScope.put( "docUNID",docUNID );
It uses my eStarService bean to take a couple of parameters and fetch a document and get the url so I can open that document . I can use this if I set the value of this method as a scope variable and use that scope variable in the custom contrl that contains the navigator code.
I would much prefer to call the method from my bean while in the custom control rather than rely on scope variables however when I access my bean in the custom control it throws an error about the class not being defined. Yet it works fine inthe parent xPage.
thoughts?
Use custom properties computed once with $ not #

Resources