How can I easily implement right-to-left text direction with Symfony2 - symfony

My question is in the title. Can you help me to implement better solution for right-to-left text direction.

For example, you can make something like this
<?php
namespace You\YourBundle\Constants;
class LanguageConstants
{
const LANGUAGE_EN = 1;
const LANGUAGE_HR = 2;
const LANGUAGE_SR = 3;
const LANGUAGE_BS = 4;
const LANGUAGE_DE = 5;
const LANGUAGE_PT = 6;
const LANGUAGE_AR = 7;
static private $constants = array(
self::LANGUAGE_EN => 'English',
self::LANGUAGE_HR => 'Hrvatski',
self::LANGUAGE_SR => 'Srpski / Српски',
self::LANGUAGE_BS => 'Bosanski / Босански',
self::LANGUAGE_DE => 'Deutsch',
self::LANGUAGE_PT => 'Português',
self::LANGUAGE_AR => 'العربية',
);
static private $constantsURL = array(
self::LANGUAGE_EN => 'en',
self::LANGUAGE_HR => 'hr',
self::LANGUAGE_SR => 'sr',
self::LANGUAGE_BS => 'bs',
self::LANGUAGE_DE => 'de',
self::LANGUAGE_PT => 'pt',
self::LANGUAGE_AR => 'ar',
);
static private $constantsRTL = array(
self::LANGUAGE_EN => false,
self::LANGUAGE_HR => false,
self::LANGUAGE_SR => false,
self::LANGUAGE_BS => false,
self::LANGUAGE_DE => false,
self::LANGUAGE_PT => false,
self::LANGUAGE_AR => true,
);
static public function getLanguageConstants()
{
natsort(self::$constants);
return self::$constants;
}
static public function getLanguageName($const)
{
return self::$constants[$const];
}
static public function getLanguageURL($const)
{
return self::$constantsURL[$const];
}
static public function getLanguageRTL($const)
{
return self::$constantsRTL[$const];
}
}
So, this is one way to go. This way you can have all your language data in one place, you can easily get en in yoururl/en/yourroute by calling getLanguageURL, and in same maner you can call getLanguageRTL in your controller with a proper _local and pass in to twig so that you could do if R2L true then dir=rtl.
You can even make a twig extension to call getLanguageRTL from twig but since controller is the place to do all "dirty works", why bother.
Best regards

Related

Wordpress stripping attributes even when explicitly allowed

I've looked through every guide on allowing HTML tags and attributes to Wordpress posts, but it's still stripping the allow attribute from iframes. When echoing the allowedposttags global, it looks like iframe[allow] is set to true. TinyMCE's settings show that extended_valid_elements is set to allow all *[*]. The POST data to the Wordpress update endpoint is not stripped. I'd really appreciate any help in identifying the problem. Here's the plugin I put together based on a few guides:
<?php
/**
* Plugin Name:Allow Tags
* Description: Allows one to add "invalid" and custom HTML elements to the Wordpress editor.
* Version: 0.1
* Author: Sam Hill
* with help from http://www.engfers.com/2008/10/16/how-to-allow-stripped-element-attributes-in-wordpress-tinymce-editor/ and many other sources
*/
class AllowTags {
public static $instance = null;
public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
private function __construct() {
add_filter('wp_kses_allowed_html', 'custom_wpkses_post_tags', 10, 2 );
add_filter('tiny_mce_before_init', 'tinymce_allow_iframe');
add_action('init', 'allow_iframe_attributes', 10, 2);
}
}
AllowTags::get_instance();
function tinymce_allow_iframe($init) {
$options = '*[*]';
$init['valid_elements'] = $options;
$init['extended_valid_elements'] = $options;
$init['verify_html'] = false;
return $init;
}
function custom_wpkses_post_tags($allowed, $context){
if (is_array($context)) {
return $allowed;
}
if ($context === 'post') {
$allowed['iframe'] = array(
'src' => true,
'height' => true,
'width' => true,
'frameborder' => true,
'allowfullscreen' => true,
'allow' => true
);
}
return $allowed;
}
function allow_iframe_attributes( $string ) {
global $allowedposttags;
$allowedposttags['iframe'] = array(
'allow' => true,
'align' => true,
'frameborder' => true,
'height' => true,
'width' => true,
'sandbox' => true,
'seamless' => true,
'scrolling' => true,
'srcdoc' => true,
'src' => true,
'class' => true,
'id' => true,
'style' => true,
'border' => true,
);
return $string;
}
}

Silverstripe Elemental trouble after creating related dataobjects

Facts: SS 4.0.1, dnadesign/silverstripe-elemental 2.x-dev, php 7.1 and Zauberfisches Vagrant box Jessy Version 3
I made an Elemental Element that is a holder for single elements:
namespace R12page\Elements;
use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Versioned\Versioned;
use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;
class ImageRasterElement extends BaseElement
{
private static $singular_name = 'Image Raster Element';
private static $plural_name = 'Images Raster Elements';
private static $description = 'Generates an Image Raster for multiple single Elements';
private static $table_name = 'ImageRasterElement';
private static $has_many = [
'SingleElements' => SingleElement::class
];
private static $extensions = [
Versioned::class . '.stagedversioned',
];
public function getType()
{
return 'ImageRasterElement';
}
public function getCMSFields()
{
$fields = parent::getCMSFields();
$singleElements = $this->SingleElements();
$singleElementGridConfig = GridFieldConfig_RecordEditor::create();
$singleElementGridConfig->addComponent(new GridFieldSortableRows('SortOrder'));
$singleElementGrid = GridField::create('SingleElements', 'Single Elements of this Page', $singleElements, $singleElementGridConfig);
$fields->addFieldsToTab('Root.Main', $singleElementGrid);
return $fields;
}
}
This Element has_many single Elements: they look like:
namespace R12page\Elements;
use R12page\Model\News;
use R12page\Model\People;
use R12page\Model\References;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
class SingleElement extends DataObject
{
private static $table_name = 'SingleElement';
private static $db = [
'Reference' => 'Boolean',
'People' => 'Boolean',
'News' => 'Boolean',
'SortOrder' => 'Int'
];
private static $has_one = [
'News' => News::class,
'People' => People::class,
'Reference' => References::class,
'ImageRasterElements' => ImageRasterElement::class
];
private static $summary_fields = [
'News.Headline' => 'News',
'People.Name' => 'People',
'Reference.Headline' => 'Reference'
];
private static $extensions = [
Versioned::class . '.stagedversioned',
];
}
Each Single Element has an has_one to a Data Object. The look like:
namespace R12page\Model;
use R12page\Elements\SingleElement;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
class News extends DataObject
{
private static $table_name = 'News';
private static $db = [
'Headline' => 'Varchar',
'SubHeadline' => 'Varchar',
'Date' => 'Date',
'DatePublished' => 'Date',
'Content' => 'HTMLText',
'IsActiv' => 'Boolean',
'DisplayOnHomePage' => 'Boolean'
];
private static $has_one = [
'Mobile' => Size::class,
'Screen' => Size::Class
];
private static $has_many = [
'SingleElements' => SingleElement::class
];
private static $owns = [
'SingleElements'
];
private static $summary_fields = [
'Headline' => 'Headline',
'Mobile.Title' => 'Mobile',
'Screen.Title' => 'Screen'
];
private static $extensions = [
Versioned::class . '.stagedversioned',
];
}
So far so good. This is what it looks like in the admin Area.
The strange thing is if I add a single Element an try to create it i get this:
When i refresh the page i can see the content of the page and i can save it with out any problems. When if use php_debug everything looks good. I also don't have and error messages in the console which i think, are related to the problem i am having . I just get those to warnings:
But i think the warnings should not be the problem. To be precise i get an error because a font is not loading.
Please help me debug this. I tried the hole day to get this to work. I can not identify the problem i am having.
This is the response i am getting back:
To me it looks okay.
This is the response from the browser networktap:
A view things i can confirm:
Elemental works on a clean install.
If i switch to live mode nothing changes.
If i try to use the content element that ships with elemental it has the same behavior.

How to execute a Drupal-view in a custom module and print the output (as html-markup)?

I want to print the output from a simple view in my custom module. But is doesnt work. I have tried many options from forums and stackoverflow. All of them print "array" instead of html-markup.
My controller:
class DefaultController extends ControllerBase {
public function myfunc1() {
$view = Views::getView('myfirstview');
$view->setDisplay('page_1');
$view->preExecute();
$view->execute();
// $myresults = $view->preview(); = array
// $myresults = $view->render(); = array
$myresults = $view->result; // = array
return array(
'#title' => 'Hello World!',
'#markup' => $myresults,
);
}
}
How can I print the result/output of a view programmatically?
I dont want to make it without "embed view" , because I want to set some exposed filters later.
get the view
$corresponding_view = Views::getView('myfirstview');
set exposed filters
$arguments = your arguments (exposed filter value);
$corresponding_view->setArguments($arguments);
embed your view
return [
'#type' => 'view',
'#name' => 'myfirstview',
'#view' => $corresponding_view,
'#display_id' => 'page_1',
'#embed' => TRUE,
];

Drupal Views Filter Handler

I wrote a custom views handler, that mark message private to 0 or 1 or 2; any is value of hers label [MARK_READ,ARK_NEW,...] :
function mydevel_views_data() {
$data['mydevel']['table']['group'] = t('mydevel');
$data['mydevel']['table']['join'] = array(
// Exist in all views.
'#global' => array(),
);
$data['mydevel']['mydevel_isnewmessage'] = array(
'title' => t('is new message field'),
'help' => t('is new message field.'),
'field' => array(
'handler' => 'mydevel_handler_field_isnewmessage',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'mydevel_handler_filter_isnewmessage',
),
);
and wrote a filed handler that work properly; message_mark function is wrote on mydevel module file and work currectly; if the message is new that filed label row by "now":
class mydevel_handler_field_isnewmessage extends views_handler_field_numeric {
var $field_alias = 'mydevel_field_isnewmessage';
function query() {
}
function option_definition() {
$options = parent::option_definition();
//dsm($this);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
}
function get_value($values, $field = NULL) {
return intval(message_mark($values->mid, $values->message_timestamp));
}
function render($values) {
$value = $this->get_value($values);
$value_theme = theme('mark', array('type' => $value));
return $value_theme;
}
}
Now, i want to write a views filter handler that filter on that filed on numeric mode [0 or 1 or 2] or on check list mode [all, read, new, updated]. but I don't want to overwite query function on filter handler and want to use from value that returned by this common handler filed (mydevel_handler_filter_isnewmessage) that added to views filed. can wrote this idea by extend the standard views handler? what i do my dears? I wrote this but not work: this is return error
class mydevel_handler_filter_isnewmessage extends views_handler_filter_numeric {
var $always_multiple = TRUE;
function option_definition() {
$options = parent::option_definition();
return $options;
}
function operators() {
$operators = parent::operators();
return $operators;
}
function query() {
}
}
tank you a lot.

generateUrl does not work in childrenHierarchy

using generateUrl in doctrine extensions tree
in action
$repo = $em->getRepository('Entity\Category');
$options = array(
'decorate' => true,
'rootOpen' => '<ul>',
'rootClose' => '</ul>',
'childOpen' => '<li>',
'childClose' => '</li>',
'nodeDecorator' => function($node) {
return ''.$node[$field].'';
}
);
$htmlTree = $repo->childrenHierarchy(
null, /* starting from root nodes */
false, /* true: load all children, false: only direct */
$options
);
error:
FatalErrorException: Error: Using $this when not in object context in
You have to register that as a service and inject the #router
nodeDecorator is a closure, therefor you cannot use this inside. Try this:
//depending in which context you are
$routing = $this->container->get('router');
[...]
'nodeDecorator' => function($node) use ($router) {
return ''.$node[$field].'';
}

Resources