When I configure Silex SecurityServiceProvider to work with {_locale} param, login.check_path returns a LogicException as follow:
LogicException: The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?
Following is my settings:
$app->register(new Silex\Provider\SecurityServiceProvider, [
'security.firewalls' => [
'login' => [
'pattern' => '^/{_locale}/login',
'security' => false,
],
'games' => [
'pattern' => '^/{_locale}/modules/',
'form' => [
'login_path' => '/{_locale}/login',
'check_path' => '/{_locale}/modules/login_check',
],
'logout' => [
'logout_path' => '/{_locale}/modules/logout',
],
...
],
...
],
]);
login_path and firewall handling seem to work fine, but can't finalize login process.
What's wrong with it?
I also ask you what's the correct route name of login_path, check_path and logout_path to serve to Twig {{ path() }} method, as I can't figure it out due to {_locale} presence.
Thank you.
Had the same problem today :) and found this solution:
add default_target_path and always_use_default_target_path to your security.firewalls form config.
'form' => array(
'login_path' => '/',
'check_path' => 'login_check',
'default_target_path' => '/' . $app['locale'],
'always_use_default_target_path' => true
),
Edit
So using $app['locale'] doesn't work well.
It's better you use $app['session']->get('locale') and set locale to session in a before middleware
$app->before(function (Request $request) use ($app) {
$app['session']->set('locale', $app['locale']);
....
});
Maybe somebody has a better solution by overloading event listeners. But I think this is a quick solution.
Related
My input is a log from IIS server with cookies included. I want my output (elasticsearch) to have a field like this:
"cookies": {
"cookie_name": "cookie_value"
}
Also for some cookies I want their values to be replaced with some other values from a dictionary.
Basically, I think the following filter config solves my problem:
kv {
source => "cookie"
target => "cookies"
trim => ";"
include_keys => [ "cookie_name1","cookie_name2" ]
}
translate {
field => "cookies.cookie_name1"
destination => "cookies.cookie_name1"
dictionary_path => "/etc/logstash/dict.yaml"
override => "true"
fallback => "%{cookies.cookie_name1}"
}
The problem is that I don't know if it’s the right way to do this, and whether it will work at all (especially the cookies.cookie_name part).
The correct way to do this is:
kv {
source => "cookie"
target => "cookies"
field_split => ";+"
include_keys => [ "cookie_name1","cookie_name2" ]
}
translate {
field => "[cookies][cookie_name1]"
destination => "[cookies][cookie_name1]"
dictionary_path => "/etc/logstash/dict.yaml"
override => "true"
fallback => "%{[cookies][cookie_name1]}"
}
https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#logstash-config-field-references
https://www.elastic.co/guide/en/logstash/7.4/plugins-filters-kv.html
https://www.elastic.co/guide/en/logstash/7.4/plugins-filters-translate.html
In Codeigniter 3.0.6, Twig 1.24.0 project if in twig code I would like to clear all cache on any page reload.
In some cases it seems to me, that after I modify some twig and reload page by CTRL+R, the new changes were not applied to this page.
After I mannually delete twig files it works ok.
twig is included to project as library
https://github.com/kenjis/codeigniter-ss-twig:
$twig_config = array();
$this->load->library('twig', $twig_config);
$twig_Environment = $this->twig->getTwig();
$this->config is filled with :
$this->config::Array
(
[paths] => Array
(
[0] => /mnt/diskD_Work/wwwroot/tb/application/views/
)
[cache] => /mnt/diskD_Work/wwwroot/tb/application/cache/twig
)
In $twig_Environment object output:
$twig_Environment::Twig_Environment Object
(
[charset:protected] => UTF-8
[loader:protected] => Twig_Loader_Filesystem Object
(
[paths:protected] => Array
(
[__main__] => Array
(
[0] => /mnt/diskD_Work/wwwroot/tb/application/views
)
)
[cache:protected] => Array
(
)
[errorCache:protected] => Array
(
)
)
[debug:protected] =>
[autoReload:protected] =>
[cache:protected] => Twig_Cache_Filesystem Object
(
[directory:Twig_Cache_Filesystem:private] => /mnt/diskD_Work/wwwroot/tb/application/cache/twig/
[options:Twig_Cache_Filesystem:private] => 0
)
In codeigniter-ss-twig object I see :
$debug= true; // for development envierement of CI project.
$twig = new \Twig_Environment($this->loader, [
'cache' => $this->config['cache'],
'debug' => $debug,
'strict_variables' => $debug,
'autoescape' => TRUE,
]);
If there are some more options/tuning to update cache any time I reload my page?
Thanks !
You can enable auto_reload, based on your code this should active this option:
$debug= true; // for development envierement of CI project.
$twig = new \Twig_Environment($this->loader, [
'cache' => $this->config['cache'],
'debug' => $debug,
'strict_variables' => $debug,
'autoescape' => TRUE,
'auto_reload' => TRUE,
]);
It is strange that auto_reload is not activated though, because by default auto_reload depends on the option debug if you don't set it manually
When developing with Twig, it's useful to recompile the template
whenever the source code changes. If you don't provide a value for the
auto_reload option, it will be determined automatically based on the
debug value.
Does anybody know how can I add meta tags on custom paths in Drupal 8? I am using the metatags module.
Thank you!
You can add any meta tag programmatically from your custom module using hook_page_attachments() as below.
function MYMODULE_page_attachments(array &$page) {
$ogTitle = [
'#tag' => 'meta',
'#attributes' => [
'property' => 'og:title',
'content' => 'This is my page title',
],
];
$page['#attached']['html_head'][] = [$ogTitle, 'og:title'];
}
I've tested succesfuly Metatag Routes module for Drupal 8. The module adds a button in the default metatag dashboard page. The user can configure metatags for custom controllers generated by code.
Another way to make it in a controller :
public function index()
{
$variables = [];
return [
'#theme' => 'my_theme',
'#variables' => $variables,
'#attached' => [
'library' => [
],
// Added for open graph and SEO.
'html_head' =>
[
[
'#tag' => 'meta',
'#attributes' => [
'name' => 'og:descritpion',
'description' => 'My sublim description',
],
],
'og:descritpion',
],
];
}
The only solution actually with metatag module for Drupal 8, is to use fields in your content type, and use them as metatag element with token possibilities.
It works well like that. I also wait for a better solution.
I think there are more than one way to make block invisible for students.
1.
Hide the block
2.
Assign role to block and set permission to block
But these are done by admin by change the settings. I need a way by code. How can I write the code to make the block invisible for student.
For activity I can make invisible the activity by changing db/access.php
'mod/questionbank:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'legacy' => array(
//'guest' => CAP_ALLOW,
//'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
Like this how can I make the block invisible for student by code.
EDIT
according to Davosmith's answer.
I put inside get_content function
if (!has_capability('blocks/blockname:view')) {
return null;
}
in blocks/blockname/block_blockname.php
and in my blocks/blockname/db/access.php contain:
'blocks/blockname:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_BLOCK,
'legacy' => array(
//'guest' => CAP_ALLOW,
//'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
// 'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
But it results in error page saying
Coding error detected, it must be fixed by a programmer: PHP catchable
fatal error
For any block, if get_contents returns null (and editing is off), the block will not be displayed.
So, put the following in the get_content function of your block (but put in a real capability that you define in db/access.php):
if (!has_capability('block/myblock:somecapability', $this->context)) {
return null;
}
First of all, I’ve seen alot of people trying to do a similar task, which is simply to create a new tab, with sub tabs in the user profile menu. I’ve managed to do this, but I can’t seem to get the url slug to work properly. When I click on the first sub tab, it simply takes me back to the main page for the user profile, and when I click on any additional sub tabs I get 404 errors. I have a feeling I’m missing something pretty simple, and I’ve been trying to learn over the last couple weeks how to make this work without any luck. If someone could help guide me on how to get this working properly, I would very grateful, and I imagine many others would find this post useful in the future.
For the record the main profile tab works properly, but the sub-tabs do not.
Here is the code I currently have in my bp-custom.php file
// My Membership Profile Tab
function profile_new_nav_item() {
global $bp;
bp_core_new_nav_item(
array(
'name' => 'My Membership',
'slug' => 'my-membership',
'default_subnav_slug' => 'extra_sub_tab', // We add this submenu item below
'screen_function' => 'view_manage_tab_main'
)
);
}
add_action( 'bp_setup_nav', 'profile_new_nav_item', 10 );
function view_manage_tab_main() {
add_action( 'bp_template_content', 'bp_template_content_main_function' );
bp_core_load_template( 'template_content' );
}
function bp_template_content_main_function() {
if ( ! is_user_logged_in() ) {
wp_login_form( array( 'echo' => true ) );
}
}
function profile_new_subnav_item() {
global $bp;
bp_core_new_subnav_item( array(
'name' => 'Membership Level',
'slug' => 'extra_sub_tab',
'parent_url' => $bp->loggedin_user->domain . $bp->bp_nav[ 'extra_tab' ][ 'slug' ] . '/',
'parent_slug' => $bp->bp_nav[ 'my-membership' ][ 'slug' ],
'position' => 10,
'screen_function' => 'view_manage_sub_tab_main'
) );
}
add_action( 'bp_setup_nav', 'profile_new_subnav_item', 10 );
function view_manage_sub_tab_main() {
add_action( 'bp_template_content', 'bp_template_content_sub_function' );
bp_core_load_template( 'template_content' );
}
function bp_template_content_sub_function() {
if ( is_user_logged_in() ) {
//Add shortcode to display content in sub tab
echo do_shortcode( '[membership]' );
} else {
wp_login_form( array( 'echo' => true ) );
}
}
// My Billing Profile Tab
function profile_new_subnav_item_billing() {
global $bp;
bp_core_new_subnav_item( array(
'name' => 'Billing',
'slug' => 'extra_sub_tab_billing',
'parent_url' => $bp->loggedin_user->domain . $bp->bp_nav[ 'extra_tab' ][ 'slug' ] . '/',
'parent_slug' => $bp->bp_nav[ 'my-membership' ][ 'slug' ],
'position' => 20,
'screen_function' => 'view_manage_sub_tab_billing'
) );
}
add_action( 'bp_setup_nav', 'profile_new_subnav_item_billing', 20 );
function view_manage_sub_tab_billing() {
add_action( 'bp_template_content', 'bp_template_content_sub_function_billing' );
bp_core_load_template( 'template_content' );
}
function bp_template_content_sub_function_billing() {
if ( is_user_logged_in() ) {
//Add shortcode to display content in sub tab
echo do_shortcode( '[billing]' );
} else {
wp_login_form( array( 'echo' => true ) );
}
}
You may use this:
// define your parent slug
$parent_slug = 'activity';
bp_core_new_subnav_item( array( .........
'parent_url' => $bp->loggedin_user->domain . $parent_slug.'/',
'parent_slug' => $parent_slug,
It works for me.