I am developing a project in Symfony 4.3. I am trying to create URLs in different languages. I have tried to use this notation:
/**
* #Route({
* "it": "/{_locale}/rassegna/stampa",
* "bg": "/{_locale}/Статии/в/печата"
* }, name="rassegna_stampa", utf8=true)
*/
The problem is that when I try to create a link in a twig to change language, for example:
GO TO BG LANGUAGE
it is rendered in something like:
http://website.it/it/%D0%A1%D1%82%D0%B0%D1%82%D0%B8%D0%B8/%D0%B2/%D0%BF%D0%B5%D1%87%D0%B0%D1%82%D0%B0
So it seems that the translated final part is ok, but the _locale parameter is not matched, as the {_locale} placeholder is filled with the current locale, and not with the locale that I requested in the link. It is 'it' but it should be 'bg'.
Related
I have a route with a parameter {id} on which I want to apply a condition. Only if {id} contains more than 3 characters, this route should be available. I read about conditions in routes both in the documentation and in a similar question. What I tried:
/**
* #Route("/{id}", name="some_route", condition="strlen(id) > 3")
*/
I also tried with requirements instead of condition and tried {id} instead of id. No luck. The error that is show is:
The function "strlen" does not exist around position 1 for expression strlen(id) > 3.
How to solve this issue?
In this case, using regular expression is the best option. Take a look in the PHP documentation to find out more (Here is the link). And suppose the characters you are referring to are alphanumeric characters (I added the - and _).
<?php
// some code ...
/**
* #Route("/{id}", name="some_route", requirements={"id"="[a-zA-Z0-9_-]{3,}"})
*/
I am trying to migrate files into a custom filetype with a lot of custom defined fields. However they seem to be getting migrated in the document filetype rather than into my custom created filetype.
I'm using the MigrateDestinationFile as my destination like this:
$this->destination = new MigrateDestinationFile();
I've tried to map the type like this answer suggested like this:
$this->addFieldMapping('type')->defaultValue('custom_file_type');
This solution doesn't work, when checking the mappable fields for the MigrateDestinationFile there is no type field specified so I think this is the reason why that solution doesn't work.
If some one could point me to an example of how to migrate into a custom file type that would be highly appreciated. Maybe I'm using the wrong destination? Or did I miss something very obvious.
The other part of the migration doesn't matter for this question.
Apparently I had two issues. The first one being that when we created the file type we called it file which for some reason you can't set as a migrate destination since it's already default in the MigrateDestinationFile constructor (see code below).
From file.inc:544
/**
* Basic initialization
*
* #param array $options
* Options applied to files.
*/
public function __construct($bundle = 'file', $file_class = 'MigrateFileUri', $options = array()) {
parent::__construct('file', $bundle, $options);
$this->fileClass = $file_class;
}
Second issue was the mapping to the field bundle itself. I simply had to set the correct destination like this after re-creating the file type with a different name:
$this->destination = new MigrateDestinationFile('product_download');
After doing this the migrated files where created in the correct content type rather than the document file type.
I'd like to be able to open the app and print the parameters when I click on the dynamic link (even though it's not published).
Is there a way to do this?
Yes! In fact, I go through this exact process in the getting started videoS (part 1), (part 2), which I recommend you check out if you haven't yet.
But, generally speaking, you can test the "Open my app if I have it installed" flow simply by clicking on a dynamic link. If your app is installed on the device, it should open up just fine; even if it's not a published app.
If you want to test the non-installed flow, this is pretty easy, too.
First, give your Firebase project an app store ID in your project settings. It can be any valid App store ID -- it doesn't have to be for your app.
Then generate a new dynamic link.
This time, when you click on this new link, it should take you to the app store for the ID you listed above. You don't need to actually install this app -- just making it to the app store listing is good enough.
Now, go ahead and reinstall and run your app. If everything is working properly, it should retrieve and display the dynamic link data for you.
I have faced the same issues, and after spending many hours trying to found a solution, and following the instruction to debug explained by Todd Kerpelman post, I could identify that the firebase has not sent a universal link on the first app launch and has sent the scheme URL with the following structure:
[bundle_id]://google/link/?deep_link_id=[firebase_universal_link]
After identifying that, I found the dynamicLinkFromCustomSchemeURL method inside of the Firesabe SDK and I could solve my problem on the first app launch by dynamic links.
/**
* #method dynamicLinkFromCustomSchemeURL:
* #abstract Get a Dynamic Link from a custom scheme URL. This method parses URLs with a custom
* scheme, for instance, "comgoogleapp://google/link?deep_link_id=abc123". It is suggested to
* call it inside your |UIApplicationDelegate|'s
* |application:openURL:sourceApplication:annotation| and |application:openURL:options:|
* methods.
* #param url Custom scheme URL.
* #return Dynamic Link object if the URL is valid and has link parameter, otherwise nil.
*/
- (nullable FIRDynamicLink *)dynamicLinkFromCustomSchemeURL:(NSURL *)url
NS_SWIFT_NAME(dynamicLink(fromCustomSchemeURL:));
/**
* #method dynamicLinkFromUniversalLinkURL:completion:
* #abstract Get a Dynamic Link from a universal link URL. This method parses the universal link
* URLs, for instance,
* "https://example.page.link?link=https://www.google.com&ibi=com.google.app&ius=comgoogleapp".
* It is suggested to call it inside your |UIApplicationDelegate|'s
* |application:continueUserActivity:restorationHandler:| method.
* #param URL Custom scheme URL.
* #param completion A block that handles the outcome of attempting to get a Dynamic Link from a
* universal link URL.
*/
- (void)dynamicLinkFromUniversalLinkURL:(NSURL *)url
completion:(FIRDynamicLinkUniversalLinkHandler)completion
NS_SWIFT_NAME(dynamicLink(fromUniversalLink:completion:));
/**
* #method dynamicLinkFromUniversalLinkURL:
* #abstract Get a Dynamic Link from a universal link URL. This method parses universal link
* URLs, for instance,
* "https://example.page.link?link=https://www.google.com&ibi=com.google.app&ius=comgoogleapp".
* It is suggested to call it inside your |UIApplicationDelegate|'s
* |application:continueUserActivity:restorationHandler:| method.
* #param url Custom scheme URL.
* #return Dynamic Link object if the URL is valid and has link parameter, otherwise nil.
*/
I'm writing a new endpoint for 3rd party desktop application, and there are several different functions in the application that post to the same endpoint on my Symfony 2.8 server.
Sometimes the desktop application goes to the correct path - example.com/path/to/endpoint. However sometimes it tries to go to add an extra slash in between the domain name and the path - example.com//path/to/endpoint.
I tried to just add an extra route with the double slash in it like this:
/**
* #Route("/path/to/route", name="example_route")
* #Route("//path/to/route", name="example_route_double_slash")
* #Method({"POST"})
*/
Symfony just ignores the double slash when it compiles the routes though, and I end up with 2 of "/path/to/route" if I check my routes with app/console debug:router
By default, the Symfony Routing component requires that the parameters
match the following regex path: [^/]+. This means that all characters
are allowed except /.
You must explicitly allow / to be part of your parameter by specifying
a more permissive regex path.
Your route definition have to use regex :
/**
* #Route("/{slash}/path/to/route", name="example_route_double_slash", requirements={"slash"="\/?"})
*/
I haven't tested the code but it basically says that you are adding an extra parameter that may or may not be a /.
The code snippet is inspired from this one at official docs :
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class DemoController
{
/**
* #Route("/hello/{username}", name="_hello", requirements={"username"=".+"})
*/
public function helloAction($username)
{
// ...
}
}
find more here : http://symfony.com/doc/current/routing/slash_in_parameter.html
I have a multi-language drupal setup (2 languages, english default). I want users to receive always content in the other language (lets say spanish) on initial page request, but keep english as default language for future language switch. So users will be redirected on initial load to site.com/es, but through the language switch will be able to go to site.com/ (which is english).
Any suggestions? Thank you.
(Apache, PHP)
Redirect users using preprocess in template.php file of your theme:
Approximate code:
/**
* Override or insert variables into the page templates.
*
* #param $vars
* An array of variables to pass to the theme template.
* #param $hook
* The name of the template being rendered ("page" in this case.)
*/
function THEMENAME_preprocess_page(&$vars, $hook) {
global $language;
if ($language->language == 'en') { // Add here some checking for page, see print_r($vars)
drupal_goto(url().'/es/'.$GET['q']); //goto es version
}
}