Drupal 8 Preview button not working - drupal

When using a custom front-end theme, the preview button for my content stops working. It just redirects to the content overview page.
Am I missing something in my theme that allows me to use the 'preview' function?

You most likely have the ?destination=admin/content in your URL. This is a core bug. The current discussion can be read at:
https://www.drupal.org/node/2325463

Jason Ruyle's answer is correct, I had the same problem and solved it by adding this code to my module:
use Drupal\Core\Entity\EntityInterface;
function my_module_entity_operation_alter(array &$operations, EntityInterface $entity) {
if (isset($operations['edit']['query'])) {
unset($operations['edit']['query']['destination']);
}
return $operations;
}
The code could also be improved to target the right entities, if needed.

Related

mmenu wordpress plugin - can't setup position from option page

I'm using the free version of mmenu plugin for wordpress. The menu is working correctly but it opens always from the left, even if i set up another position from the option page.
If I inspect the js file "mmenu.js" it seems that the option is passed correctly as I can see it in the code this string:
extensions: { "all": ["position-top"] }
But if I inspect the HTML source there are still the classes as the menu is setup to be opened from the left: (mm-wrapper--position-left, mm-menu--position-left, ...)
I wonder if this is a known issue or just a problem of my website, and if maybe you have a possible solution.
Thanks in advance
Francesco

Change theme for node add page in Drupal 7

I tried using hook_custom_theme to change the theme for the node add page for a specific content type, like this, without success:
function mymodule_custom_theme() {
if (current_path() == 'node/add/mytype')
return 'anothertheme';
}
I know the function is running, and I know the comparison is returning TRUE. Why is it not working?
I think you are not writing the theme name correctly.
But there is a module which could do this work for you: https://drupal.org/project/themekey
Regards.
1) Do you use the correct machine name for the theme?
2) Are you sure that there are not other modules to override this later?
3) Is the page cached? If so this may not work properly.
Same question and discussion here: https://drupal.stackexchange.com/questions/812/how-do-i-change-a-theme-based-on-the-url
Useful modules:Page Theme, Context, ThemeKey.

qTranslate ignores language in url

I want to create a website written in two languages. I used qTranslate and it seems to be working okay. But, I have couple of conditional elements in my theme, like:
<li><a href="/<?php if(qtrans_getLanguage()=='en') { ?>en<?php } else { ?>pl<?php } ?>></li>
Which detects if either language is pl or en and creates the link according to that. But, when I click the link http://localhost/en/something for example, it ommits en and loads http://localhost/something with default language. What can I do to change it?
edit: this happens only on custom post types.
I solved the issue. Adding / at the end of the link helped.
Came across this problem too. Adding / didn't make any difference.
Using ?setlang=no instead solved my problem.
Source: qTranslate-X FAQ

Wordpress syntax highlighting

I recently switched my blog from joomla to wordpress and i'm having problems when posting code snippets.
The editor seems to remove some of the characters when i save my posts.
I am using a plugin that i got from this link: http://alexgorbatchev.com/SyntaxHighlighter/
Example:
<pre class="brush: javascript">;
var window.onload = function() {
alert("Loading is complete");
};
</pre>
Is formatted to:
<pre>;
var window.onload = function() {
alert("Loading is complete");
};
</pre>
How can i solve this problem?
If you're on WordPress.com, I believe you should be using a shortcode like so: http://en.support.wordpress.com/code/posting-source-code/
If you're on self-hosted WordPress and using the WordPress plugin Syntax Highlighter (http://wordpress.org/extend/plugins/syntax-highlighter/), again I think the correct way to insert code is by wrapping it in a shortcode. So instead of < pre > you would use:
[javascript]
// your code here
[/javascript]
If neither of these sounds like an ideal solution (or works) there are a bunch of other syntax highlighter plugins for self-hosted WordPress that might be better: http://wordpress.org/extend/plugins/search.php?q=syntax+highlighter
Hope this helps - best of luck!
Agree with #Michelle.
This actually works for me.
[sourcecode language='javascript']
//Replace 'javascript' by the corresponding language
//Your code goes here
[/sourcecode]
It will work on save or update for hosted and non hosted sites.
Example.
To apply it to your text, you just have to switch to the 'Text' visual editor.
Your pages will load faster if you do the syntax highlighting before posting, using pygmentize: http://permafrostcodingstudio.com/articles/syntax-highlighting-in-posts/
It's a little more complicated, but worth being able to disable a plugin. Wordpress will run faster and be more secure with fewer plugins installed.

How does one inject variables into page templates from a custom Drupal module?

We've created a custom module for organizing and publishing our newsletter content.
The issue I'm running into now -- and I'm new to theming and Drupal module development, so it could just be a knowledge issue as opposed to a Drupal issue -- is how to get each newsletter themed.
At this point the URL structure of our newsletter will be:
/newsletters/{newsletter-name}/{edition-name}/{issue-date} which means that we can create template files in our theme using filenames like page-newsletters-{newsletter-name}-{edition-name}.tpl.php, which is great. The one issue I'm running into is that all of the content comes through in the $content variable of the theme. I'd like to have it come through as different variables (so that I can, inside the theme, place certain content in certain areas.)
Is there a proper way for doing this?
Edit: To answer some questions: The issue is a node (there are issue, edition and newsletter nodes) and the path is being set using hook_menu with wildcards and a router.
The best answer I could find was to add a check inside of phptemplate_preprocess_page to send the vars back to the module and have them be updated.
Like so:
function phptemplate_preprocess_page(&$vars) {
if (module_exists('test_module')) {
_test_module_injector($vars);
}
}
then in my test_module.module file I created this function:
function _test_module_injector(&$vars) {
$vars[] = call_to_other_functions_to_load_vars();
}
It seemed to work. I wish there was a way to do this without having to touch the theme's template.php file, but otherwise this works well.
If there were better documentation for template preprocess functions, Drupal would be a lot more accessible - as it is, you need to piece together the information from a lot of different explanations. One place to start is here:
http://drupal.org/node/223430
but if you take the time to work through the tutorial below, you'll find you can do most things:
http://11heavens.com/theming-the-contact-form-in-Drupal-6
This is an old post, and the OP's issues seems to have been solved.
However, just for others finding this through Google (or otherwise):
Install the 'Devel' module: http://drupal.org/project/devel
Also the 'Devel Themer' module: http://drupal.org/project/devel_themer
Use Devel Themer to go through the $content variable and find what you need to pull out.
There are a bunch of Devel/Themer docs/tuts out there, but its usage is pretty straightforward. Note, though, that some stuff in there will need to be sanitized before printing in the theme.
The suggestion to show the node as a View and then modifying the view templates sounds pretty crazy, though it'll work.

Resources