I have a TYPO3 installation with multiple languages.
Now I want to create a function that if i.e. a french editor, with french settings, goes to the View (or preview of a page) that he gets the french version and not the default language.
My first idea was to use the PageLayoutViewDrawItemHookInterface and then change the URL for the right language
in ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['tx_editordashboard'] =
\Vendor\Editordashboard\Hooks\Backend\CheckUserCountry::class;
in my CheckUserCountry.php class
<?php
namespace TRUMPF\Editordashboard\Hooks\Backend;
use \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use \TYPO3\CMS\Backend\View\PageLayoutView;
class CheckUserCountry implements PageLayoutViewDrawItemHookInterface
{
/**
* Preprocesses the preview rendering of a content element.
*
* #param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling
parent object
* #param bool $drawItem Whether to draw the item using the default
functionalities
* #param string $headerContent Header content
* #param string $itemContent Item content
* #param array $row Record row of tt_content
*/
public function preProcess(PageLayoutView &$parentObject, &$drawItem,
&$headerContent, &$itemContent, array &$row) {echo "bam";}
}
But the Hook doesn't work if I click on the "View" Button. Any ideas so solve the problem?
Related
Like many other people, I have a problem with TinyMCE stripping HTML tags - specifically the empty ones I'm using with Font Awesome.
I have researched and tried solutions and nothing has worked. I'm not especially strong with PHP, but the problem I'm running into is this: everybody says modifiy the tinyMCE.init function in the tinymce.js file. However being in the newest version of WP, I don't have that. What I have class-wp-editor.php, wherein lives this:
/*
* For people who really REALLY know what they're doing with TinyMCE
* You can modify $mceInit to add, remove, change elements of the config
* before tinyMCE.init. Setting "valid_elements", "invalid_elements"
* and "extended_valid_elements" can be done through this filter. Best
* is to use the default cleanup by not specifying valid_elements,
* as TinyMCE checks against the full set of HTML 5.0 elements and attributes.
*/
if ( $set['teeny'] ) {
/**
* Filter the teenyMCE config before init.
*
* #since 2.7.0
*
* #param array $mceInit An array with teenyMCE config.
* #param string $editor_id Unique editor identifier, e.g. 'content'.
*/
$mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
} else {
/**
* Filter the TinyMCE config before init.
*
* #since 2.5.0
*
* #param array $mceInit An array with TinyMCE config.
* #param string $editor_id Unique editor identifier, e.g. 'content'.
*/
$mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );
}
Now I know I have to do something with valid_elements, or extended_valid_elements, or verify_html, but I don't know how to do it. I can see from the comments where to put it, but I don't know which to use or the proper syntax.
I found this fiddle: http://fiddle.tinymce.com/j9baab/1 but like I said I don't have that function anywhere in WP.
Please help!
You really don't want to modify the class-wp-editor.php file as each time you update WordPress it will get overwritten.
The easiest way to extend/modify the settings of TinyMCE is to build a simple WordPress Plugin and tie into the hooks WordPress provides to change the editor's settings.
To solve your particular desire to add options to the init you want to look at
the 'tiny_mce_before_init' hook. You might do something like this in the plugin:
add_filter('tiny_mce_before_init', 'add_my_options');
function add_my_options($opt) {
// $opt is the existing array of options for TinyMCE
// We simply add a new array element where the name is the name
// of the TinyMCE configuration setting. The value of the array
// object is the value to be used in the TinyMCE config.
$opt['extended_valid_elements'] = '*[*]';
return $opt;
}
Writing a simple WP plugin is not too hard - there are plenty of examples on the web. For something this simple its really just a single PHP file. Once you have the plugin built you just install and activate it. Once activated, your code is run each time TinyMCE is invoked and your options are injected into the init code.
EDIT: Here is the code from the OPs comment (easier to read than how the comments are formatted):
<?php
/**
* Plugin Name: Disable TinyMCE Filters
* Plugin URI: http://mindspyder.com
* Description: This plugin disables annoying TinyMCE Filters.
* Version: 1.0.0
* Author: Brandon Snow
* Author URI: http://mindspyder.com
* License: GPL2
*/
add_filter('tiny_mce_before_init', 'add_my_options');
function add_my_options($opt) {
// $opt is the existing array of options for TinyMCE
// We simply add a new array element where the name is the name
// of the TinyMCE configuration setting. The value of the array
// object is the value to be used in the TinyMCE config.
$opt['extended_valid_elements'] = '*[*]';
return $opt;
}
?>
When I control click into a php function, it drives me to its definition and I can see the documentation and the function declaration, but no logic inside. The brackets are empty. I would like to know how if its posible to do something similar in my code and how it can be done.
What i dont understand is that there is no code inside this class file, and no include statements, but the methods works when I use them in my code. And when I click onto these methods I'm linked to this file. How can I do something similar or how does it works??
This is an exmample of what I would like to do:
/**
* Retrieve item from the server
* #link http://www.php.net/manual/en/memcache.get.php
* #param key string <p>
* The key or array of keys to fetch.
* </p>
* #param flags int[optional] <p>
* If present, flags fetched along with the values will be written to this parameter. These
* flags are the same as the ones given to for example Memcache::set.
* The lowest byte of the int is reserved for pecl/memcache internal usage (e.g. to indicate
* compression and serialization status).
* </p>
* #return string the string associated with the key or
* an array of found key-value pairs when key is an array.
* Returns false on failure, key is not found or
* key is an empty array.
*/
public function get ($key, &$flags = null) {}
/**
* Delete item from the server
* #link http://www.php.net/manual/en/memcache.delete.php
* #param key string <p>
* The key associated with the item to delete.
* </p>
* #param timeout int[optional] <p>
* This deprecated parameter is not supported, and defaults to 0 seconds.
* Do not use this parameter.
* </p>
* #return bool Returns true on success or false on failure.
*/
public function delete ($key, $timeout = null) {}
These are stubs for documentation. There is no technique of hiding the code here.
The actual code isn't PHP and can be found for example here https://github.com/php/php-src/tree/master/ext/standard
or can be downloaded at the php.net website.
I'm in the process of fixing up an API, and I'd like to deprecate some old routes. I'm basically moving the endpoints around, but want to encourage new consumers to use the new routes. However, I need to support the old routes for a short period during this transition. Below is an example of something that I want. I would like the new url documented and the old one either marked as deprecated or removed from the documentation entirely. Is there an easy way to do this, or am I stuck during the transition?
/**
* Adds a new Item
*
* This creates a new item
*
* #url POST /:id/patch {#deprecated}
* #url PATCH /:id
*/
Move deprecated routes to a new method which internally calls the old method for functionality mark it as deprecated through description with the help of HTML if needed. Here is an example
/**
* Adds a new Item
*
* This creates a new item
*
* #url PATCH /{id}
*/
function patchItem($id)
{
//actual process here
}
/**
* Adds a new Item [DEPRECATED]
*
* This creates a new item
*
* #url POST /{id}/patch
*/
function deprecatedPatchItem($id)
{
return $this->patchItem($id);
}
Once you decided to remove the deprecated simply delete the new method
I want two endpoints for my custom api which are
Create custom rules in a magento cart (URL= magento.com/coupondemo/generate)
Create coupon codes for a particular rule (URL= magento.com//coupondemo/rules/:rule_id/codes)
I've followed this tutorial to and coupon codes in Magento and I have code that can create a rule in Magento too. However, I've no clue how to create the two endpoints in my custom rest api as I am only able to create one.
I have the following routes in api2.xml
<routes>
<route_collection>
<route>/coupondemo/generate</route>
<action_type>entity</action_type>
</route_collection>
<route_collection>
<route>/coupondemo/rules/:rule_id/codes</route>
<action_type>collection</action_type>
</route_collection>
</routes>
my v1.php's skeleton is as follows
<?php
/* Coupon AutoGen REST API
*
* #category CouponDemo
* #package CouponDemo_AutoGen
* #author Chuck Hudson (used with permission). For more recipes, see Chuck's book http://shop.oreilly.com/product/0636920023968.do
*/
class CouponDemo_AutoGen_Model_Api2_Coupon_Rest_Admin_V1 extends CouponDemo_AutoGen_Model_Api2_Coupon
{
/**
* Generate one or more coupon codes using the Generate Coupons rule defined in Magento.
* Expected parameters are:
* {
* 'qty': int, - number of coupon codes to instruct Magento to generate
* 'length': int, - length of each generated coupon code
* 'format': string, - alphanum (for alphanumeric codes), alpha (for alphabetical codes), and num (for numeric codes)
* }
*
* #param array $couponData
* #return string|void
*/
protected function _create($couponData)
{
}
protected function _retrieveCollection()
{
}
protected function _retrieve($couponDatas)
{
}
}
The problem is that both the routes call the _create methods in my v1.php. I want to have the first route call a custom method with an array as a parameter. So how can I do that?
I tried using this route
<!-- Call For V1.php _retrieve() -->
<route_entity_count>
<route>/coupondemo/generate</route>
<action_type>entity</action_type>
</route_entity_count>
which calls the _retrieve method but it doesn't allow the parameter to be passed in.
How should I handle the first route then?
First let me say that the new API Explorer in Restler is great. Very happy about its addition. Now, in typical fashion, let me complain about something that isn't working for me ...
The fact that Restler can return results in multiple formats is a very nice feature but I'm currently not using it (choosing to only use JSON as my return format). In the API Explorer I'd like all references to .json to not show up as this just complicates the look of the service architecture.
Here's a quick example:
class Users {
/**
* Preferences
*
* Preferences returns a dictionary of name-value pairs that provide input to applications that want to make user-specific decisions
*
* #url GET /{user_id}/preferences
**/
function preferences ($user_id , $which = 'all') {
return "$which preferences for {$user_id}";
}
/**
* GET Sensors
*
* Get a list of all sensors associated with a user.
*
* #url GET /{user_id}/sensor
**/
function sensor ($user_id) {
return "sensor";
}
/**
* GET Sensors by Type
*
* #param $user_id The user who's sensors you are interested in
* #param $type The type of sensor you want listed.
*
* #url GET /{user_id}/sensor/{type}
**/
function sensor_by_type ($user_id, $type) {
return "specific sensor";
}
/**
* ADD a Sensor
*
* #param $user_id The user who you'll be adding the sensor to
*
* #url POST /sensor
**/
function postSensor() {
return "post sensor";
}
}
In this example the API Explorer looks like this:
The basic problem I'd like to remove is remove all ".json" references as the calling structure without the optional .json works perfectly fine.
Also, for those that DO want the .json showing up there's a secondary problem of WHERE does this post-item modifier show up? In the example above you have .json attaching to the "users" element in the GET's and to the "sensor" element in the PUT. This has nothing to do with the HTTP operation but rather it seems to choose the element which immediately precedes the first variable which may not be intuitive to the user and actually isn't a requirement in Restler (at least its my impression that you can attache .json anywhere in the chain and get the desired effect).
We are using safer defaults that will work for everyone, but made it completely configurable.
if you prefer .json to be added at the end, add the following to index.php (gateway)
use Luracast\Restler\Resources;
Resources::$placeFormatExtensionBeforeDynamicParts = false;
If you prefer not to add .json extension, add the following to index.php
use Luracast\Restler\Resources;
Resources::$useFormatAsExtension = false;