Elementor repeater with unique elements - css

I need to change the position, color, background-image of elements inside each repeater separately.
My widget code is here:
$repeater->add_control(
'clock_gy_minute_hand_position', array(
'label' => __('Minute Hand Position', 'origami-clock'),
'type' => Controls_Manager::DIMENSIONS,
'default' => array('isLinked' => false),
'size_units' => ['px'],
'allowed_dimensions' => ['top', 'left'],
'selectors' => [
'{{WRAPPER}} .clock' => 'top:{{TOP}}%;right:{{RIGHT}}%;bottom:{{BOTTOM}}%;left:
{{LEFT}}%;',
],
)
)
);
when got the data of each repeater by looping, It's applied the CSS position of each clock hand to the same position. It applies the last repeater item's position to all the elements. I need to identify each repeater element uniquely.
I see some article says like this
'{{WRAPPER}} .clock'.$item['_id'] => 'top:{{TOP}}%;right:{{RIGHT}}%;bottom:{{BOTTOM}}%;left:{{LEFT}}%;',
Unfortunately, this also not working for me.

selector should be
'selectors' => [
'{{WRAPPER}} {{CURRENT_ITEM}} .clock' => 'background-color: {{VALUE}};',
]
add this class to your repeated item
elementor-repeater-item-' . $item['_id']
Hope this will work for you

Related

Yii2 - Cell Edit

How to edit cell CSS (like background color) in gridview?
Note that I only need to edit one cell not the whole column or row.
Specifically, there is a column in grid view that's labelled 'colors', I want every cell's background color to be the same as the color written there.
In gridView, in every column, you can set the contentOptions and value paramter
this is a sample where:
for a first column you assign the color for all cell of the column,
in the the second column you can assign the color for single cell based on a color value ( in this sample the color value is provided by model) evaluated inside the function. Then composing the proper html code and render in row format you set the color you desire
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'your_attribute',
'label' => 'your_labe',
'contentOptions' => ['style' => 'background-color: #000000;'],
],
....
....
[
'attribute' => 'your_attribute_cell',
'label' => 'your_label_cell',
'format' => 'raw',
'value' => function ($model) {
return "<span style='background-color:" . $model->yourColor "' >" . $model->your_attribute_cell. " </span>";
},
'contentOptions' => ['style' => ' text-align: center; width: 100px;'],
'headerOptions' => ['style' => 'text-align: center;'],
],
],

Nested elements in TinyMCE "Styles" dropdown

I've been using "tiny_mce_before_init" in WordPress to add my own custom styles to the style dropdown in the editor.
Everything has been working fine but now I need to add a style that doesn't just add one element but two. Do you know if that's possible?
Here's how I'm adding single elements:
<?php
add_filter('tiny_mce_before_init', 'my_tinymce_styles');
function my_tinymce_styles ($init) {
$styles = array(
array(
'title' => 'Small',
'inline' => 'small',
'wrapper' => false
),
array(
'title' => 'Bar',
'block' => 'div',
'classes' => 'bar',
'wrapper' => true
)
# Etc...
);
# Insert the array, JSON ENCODED, into 'style_formats'
$init['style_formats'] = json_encode($styles);
return $init;
}
And this works as expected. The user selects some text, chooses "Bar" from the "Styles" dropdown and the text is wrapped in <div class="bar">...</div>.
However, now I need to do that same but add <div class="section"><div class="inner">TEXT_HERE</div></div> - how can I do that?

Custom styles for Wordpress TinyMCE

I've read several tutorials for adding custom styles to the WYSIWYG (TinyMCE) editor. None of them seem to work in the newest version(s) of Wordpress. I'm using v3.3.2. The instructions from the codex work, but in a limited way...
NOTE: To be 100% clear, I'm trying to add a "Styles" dropdown which the author can use to apply my custom styles to the text. (Please don't confuse my question with how to style the editor its self, using editor-style.css... )
I managed to get the code working, but only using the commented-out line in my_mce_before_init(). The problem with this version is that it adds the class with a generic <span>. I'm trying to use the more powerful version of the code (as shown below), but something isn't quite right. The styles drop-down box appears, but it's blank. If I click it the first item is says "Styles" but does nothing. I suspect there's something off about my array. Hopefully someone more knowledgeable than me can set me straight.
Here's the relevant code in my theme's functions.php...
Here's how I add the button:
// Add the Style selectbox to the second row of MCE buttons
function my_mce_buttons_2($buttons)
{
array_unshift($buttons, 'styleselect');
return $buttons;
}
add_filter('mce_buttons_2', 'my_mce_buttons_2');
Here's how I add the styles (it works when I uncomment the ):
//Define the actual styles that will be in the box
function my_mce_before_init($init_array)
{
// add classes using a ; separated values
//$init_array['theme_advanced_styles'] = "Section Head=section-head;Sub Section Head=sub-section-head";
$temp_array['theme_advanced_styles'] = array(
array(
'title' => 'Section Head',
'block' => 'h3',
'classes' => 'section-head'
),
array(
'title' => 'Sub Section Head',
'block' => 'h4',
'classes' => 'sub-section-head'
)
);
$styles_array = json_encode( $temp_array['theme_advanced_styles'] );
// THIS IS THE PROBLEM !!!! READ BELOW
$init_array['theme_advanced_styles'] = $styles_array;
return $init_array;
}
add_filter('tiny_mce_before_init', 'my_mce_before_init');
UPDATE: I figured it out (see my answer below). Before you scroll down, notice in the code above, theme_advanced_styles is the wrong key. It should be style_formats when defining the custom styles in the way that I'm doing. I suspect this is a common mistake.
It seems you're using this (awesome) tutorial: http://alisothegeek.com/2011/05/tinymce-styles-dropdown-wordpress-visual-editor/
Worked great for me so I compared your code with mine: it seems you lack a
'wrapper' => true
as a fourth parameter to each sub-array. This is needed for adding a class on a parent element of your selection (it can broaden your selection) and not creating a new element around your exact selection before adding it a class.
Thus if you select part of a paragraph or part of 2 paragraphs, it'll select the whole paragraph(s) (not so sure about the 2 paragraphs thing, please test :) but at least it won't create inline element around your exact selection).
From the documentation (above link):
wrapper [optional, default = false]
if set to true, creates a new block-level element
around any selected block-level elements
My customization:
$style_formats = array(
array(
'title' => 'Column',
'block' => 'div',
'classes' => 'col',
'wrapper' => true
),
array(
'title' => 'Some div with a class',
'block' => 'div',
'classes' => 'some_class',
'wrapper' => true
),
array(
'title' => 'Title with other CSS',
'selector' => 'h3',
'classes' => 'other_style'
),
array(
'title' => 'Read more link',
'selector' => 'a',
'classes' => 'more'
)
);
Hope it works for you
AHA!
I found the problem: the two different versions of defining the custom classes must be added to different keys in the settings array.
This version...
"Section Head=section-head;Sub Section Head=sub-section-head";
...needs to be the value of 'theme_advanced_styles'.
Whereas this version...
$style_formats = array(
array(
'title' => 'Column',
'block' => 'div',
'classes' => 'col',
'wrapper' => true
),
);
...needs to be the value of 'style_formats' in the TinyMCE settings array.
I had changed to the second style but hadn't noticed the different key for the array.
Wordpress provides a function for adding a custom stylesheet to the editor: http://codex.wordpress.org/Function_Reference/add_editor_style

Drupal 7 : Getting the values from radio buttons form api

So this is my form :
$active = array(0 => t('Poster'), 1 => t('Postcard'), 2=>t('Post it'));
$form['radioimage']['active'] = array(
'#type' => 'radios',
'#default_value' => isset($node->active) ? $node->active : 1,
'#options' => $active,
);
I want to know which radio button was selected. I am trying to access the data but I don't know what its called I can't even use devel for some reason.
I tried below but they all failed
$form_state['values']['radioimage']['active'][0]
$form_state['values']['radioimage']['active']
Drupal flattens the values in the $form_state array by default so
$form['radioimage']['active']
will actually come out in
$form_state['values']['active']
If you want to explicitly keep your naming hierarchy then you should set the #tree key on the parent element:
$form['radioimage'] = array(
'#type' => 'container',
'#tree' => TRUE
);
In that case the value will be in
$form_state['values']['radioimage']['active']

How do I keep a Drupal form "markup" element from rendering inside the wrapper of the "submit" element?

I have programatically added a "markup" element to a Drupal form. When it renders on the page, the element appears in the wrapper for the submit button. Clarification: It should appear between the 'field_school_name_value' element and the 'distance' element. I have set the weights of every element in hopes that that would force the layout to be right, but it doesn't seems to help. What am I doing wrong?
<?php
function abq_misc_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'views_exposed_form') {
$state_select = array(
'#attributes' => array(
'style' => 'width:10em;',
),
'#default_value' => 'All',
'#multiple' => FALSE,
'#options' => array_merge(array('All' => 'State'), location_get_provinces()),
'#title' => NULL,
'#type' => 'select',
'#weight' => 0,
);
$form['province'] = $state_select;
$school = &$form['field_school_name_value'];
$school['#attributes'] = array(
'size' => 15,
);
$school['#weight'] = 1;
// THIS GUY
$form['divider'] = array(
'#type' => 'item',
'#markup' => '<div>–or–</div>',
'#weight' => 2,
);
$form['distance']['#weight'] = 3;
$search_distance = &$form['distance']['search_distance'];
$search_distance['#attributes'] = array(
'placeholder' => 'miles',
'size' => '5',
);
$search_distance['#prefix'] = 'Within';
$search_distance['#suffix'] = 'of';
unset($search_distance['#title']);
$search_distance['#weight'] = 0;
$postal_code = &$form['distance']['postal_code'];
unset($postal_code['#title']);
$postal_code['#attributes'] = array(
'placeholder' => 'Zip Code',
'size' => '5',
);
$postal_code['#weight'] = 1;
hide($form['distance']['search_units']);
$form['submit']['#weight'] = 4;
}
}
I'm not sure why that's happening, there's no good reason for your element to be rendered inside the wrapper for the submit button.
An easy fix, though, would be to use the #prefix attribute on the submit button which would guarantee that your markup was rendered immediately before the wrapper for the submit button:
$form['submit']['#prefix'] = '<div>–or–</div>';
UPDATE
Just to address your edit, I think the same solution can apply if you set the #prefix of the distance element instead:
$form['distance']['#prefix'] = '<div>–or–</div>';
It's possible that there's some extra formatting done by another module that implements hook_form_alter which happens to run after yours, messing up your good work. By applying the prefix to the distance element you'll be ensuring it comes immediately before the field_school_name_value element.
I should mention that I've had problems with exactly this when taking a reference to an array member of the provided $form (which you're doing with $school = &$form['field_school_name_value'];). As an extra sanity check I'd recommend changing that bit of code to this and see if it helps (try this before the other suggestion above as it might just fix it):
$form['field_school_name_value']['#attributes'] = array('size' => 15);
$form['field_school_name_value']['#weight'] = 1;
instead of
$school = &$form['field_school_name_value'];
$school['#attributes'] = array(
'size' => 15,
);
$school['#weight'] = 1;
Although this is an almost 7 years old issue, I just run this problem.
Here is the solution: https://www.drupal.org/project/views/issues/2070533
First, you should declare your markup in your form_alter hook but the '#printed' key must be declared in your defining array. Then you should implement the template_preprocess_views_exposed_form() function in your module or in theme. Here you can render the required form element by drupal_render and add it to $variables. And finally you can print out the variable in the theme (as custom variable or among widgets).
But the simpliest version: clone the views-exposed-form.tpl.php to the template directory of your theme, name it as is suggested (eg. views-exposed-form--news.tpl.php) and print your linebreak where you want.

Resources