Pass through a mandatory parameters in my Behat scenario - symfony

I am trying to determine how to pass through a mandatory parameter required to follow a defined route within my Behat features file.
This is my scenario:
Scenario: I should be able to create a cars asset
Given I am on the ayrshireminis_cars_asset_create page
When I submit a "ayrshireminis.cars.asset.type" form with values:
| name | type | position | active |
| Cars Info Doc | PDF | 1 | 1 |
Then The form should be valid
and this is the error:
Given I am on the ayrshireminis_cars_asset_create page
Some mandatory parameters are missing ("categoryId") to generate a URL for route "ayrshireminis_cars_asset_create".
(Symfony\Component\Routing\Exception\MissingMandatoryParametersException)
It's clear why I get this error as my routing is configured like this:
ayrshireminis_cars_asset_create:
pattern: /category/{categoryId}/asset/new/
How can I pass through a categoryId?

I found that I was looking at this from the wrong angle, this is how I constructed the test scenario in the end up:
Scenario: Submitting a valid cars asset form
When I submit a "ayrshireminis.cars.cars_asset.type" form with values:
| name | type | position | active |
| Cars Info Doc | pdf | 1 | 1 |
Then the form should be valid
And the cars entity form entity should have the following values
| name | type | position | active |
| Cars Info Doc | pdf | 1 | 1 |
And the cars entity form entity should be persisted correctly

Related

Many-to-many mapping from multiple entities

I have an Asset entity, and I want multiple other entities (let's say Product and Page) to have many-to-many relations to Asset, without having multiple tables (product_asset, page_asset).
The reason I want this is because want to simply display all assets, without first having to find all entities that have a relation to the Asset entity.
The Translatable Doctrine Extension is a perfect example of what I mean. There's one Translation entity containing an ObjectClass property that stores object's class name. I've been looking through to code for some time now, but just can't seem to figure out how they actually make it work.
So concrete, how can I map entities based on their class name like the Translatable Extension does? To have a structure like this:
|----|--------------------|----------|-----------|
| id | objectClass | objectId | value |
|----|--------------------|----------|-----------|
| 1 | App\Entity\Product | 1 | test.jpg |
| 2 | App\Entity\Page | 1 | test2.png |
| 3 | App\Entity\Page | 2 | test3.gif |
|----|--------------------|----------|-----------|
Thanks in advance!

Best way to define data structure in firebase database

I'm not sure that is the best way to define the following use case in firebase database. The app has the following structure.
STUDIO - Container
ADMIN - can create, read and update Trainers and Members
TRAINER - can create, read and update members
MEMBER - can signup, read and edit own data
Important ADMIN, TRAINER, MEMBER are all users who can login.
Where I should save the relationship form TRAINER to STUDIO, MEMBER to STUDIO and ADMIN to STUDIO.
|____firebase
| |____studios
| | |____Studio_A
| | | |____trainers
| | | | |____Trainer_B
| | | | |____Trainer_A
| | | |____Administrator
| | | |____members
| | | | |____Member_B
| | | | |____Member_C
| | | | |____Member_A
The structure looks quite good to me. What you'll need to add is something like a users node.
Like this:
- studios
- studio-1
- trainers
- userid
- admin
- userid
- members
- userid
- users
- userid
- studios
- studio-1: "member"
- name // just an example property
- age // just an example property
If a user can have mulitple roles in one studio, you would need to create an array inside the studios node.

What are Personal Translations in Gedmo Doctrine Extensions?

In the Translatable behaviour of the Gedmo Doctrine Extensions, it has instructions on "Personal Translations". Could someone clarify what personal translations are?
tl;dr
Personal translations are used when you want to handle the translation entity (with it's own table by yourself) instead of the default behaviour, by using a single table for all translations.
By using the default behaviour, you get a single table called ext_translations which holds all of your translation data. I'll give you an example based on the documentation of DoctrineExtensions.
Let's say we create an Article entity with 2 translatable fields - title and content. That would mean that we should have the following table structure of articles:
+----+-------+---------+
| id | title | content |
+----+-------+---------+
Now, by default the TranslatableListener sets en_us locale every time you create new entity, thus populating only articles table:
$article = new Article();
$article->setTitle('Title english');
$article->setContent('Content english');
Would lead to the following:
+----+---------------+-----------------+
| id | title | content |
+----+---------------+-----------------+
| 1 | Title english | Content english |
+----+---------------+-----------------+
By now, only articles get to be updated with new records, but when you want to translate those fields with different locale, our common table ext_translations get updated as well.
The table has the following structure:
+----+--------+---------------+---------+-------------+------------+
| id | locale | object_class | field | foreign_key | content |
+----+--------+---------------+---------+-------------+------------+
So, what happens when we update our record with some new translations:
$article->setTitle('My title');
$article->setContent('My content');
$article->setTranslatableLocale('de_de');
When we persist our updated entity, we get the following structure in ext_translations:
+----+--------+---------------+---------+-------------+------------+
| id | locale | object_class | field | foreign_key | content |
+----+--------+---------------+---------+-------------+------------+
| 1 | de_de | Bundle\Entity | title | 1 | My title |
| 2 | de_de | Bundle\Entity | content | 1 | My content |
+----+--------+---------------+---------+-------------+------------+
Now you know how the default behaviour works. It stores all of your translations (not just for single entity, all of them) in a single table.
But when you're using a personal translations you can store your (let's say for the sake of our example) Article translations to its own, separate table, article_translations.
If you are familiar with DoctrineExtensions provided by KnpLabs, then you've already seen what stands for PersonalTranslations. Link for their documentation about this subject can be found here.
Well hopes this can clarify things a bit for you. Let me know if you have more questions about this.

SonataAdmin - Choice field from non managed entity

Imagine a user who is linked to a company:
User
- id
- username
- company_id
The company list comes from a procedure call (external db), no hands on the related table
EXEC getCompanies;
+----+-------+
| id | name |
+----+-------+
| 1 | comp1 |
| 2 | comp2 |
| 3 | comp3 |
+----+-------+
How would you integrate this to allow SonataAdmin to render a proper input selection for company in User editition, and display the company name in User list ?
Do you know where I could find some examples about this particular case ?
I did a custom company field type which fetchs his values from the procedure call, but I'm not sure it's the best idea and I'm not able to display the comany name in the list.
You could use a choice type and if there are too many companies to display, you can use GenemuFormBundle with Select2 library to have filtering select widget.

Drupal 7: cancel user registration if a wrong field value has been submitted

I have a Drupal 7 with 1 field added to registration form - a List with possible values Robot / Male / Female:
# select * from field_data_field_gender;
entity_type | bundle | deleted | entity_id | revision_id | language | delta | field_gender_value
-------------+--------+---------+-----------+-------------+----------+-------+--------------------
user | user | 0 | 6 | 6 | und | 0 | Male
user | user | 0 | 5 | 5 | und | 0 | Male
user | user | 0 | 7 | 7 | und | 0 | Female
user | user | 0 | 1 | 1 | und | 0 | Male
The first value Robot is a default value - to prevent SPAM robots from registering at my site. Is there a way to cancel user registration, when a new user submits the registration web form with the default Robot value? (i.e. only Male and Female values are allowed).
I've looked at the core Trigger module, but don't see anything suitable there.
I've looked at the hook_user_presave and hook_user_insert API docs, but don't see a way there to cancel an ongoing user registration. (I was expecting to do that by returning a special value from those methods...)
Thank you!
Alex
Use a hook_form_alter and add a new validate function where you'll check the value of the field you want to check.
You can also implement your own captcha tests using the drupal module http://drupal.org/project/captcha
Which is what you are doing. This will make the test your are creating a little more portable.

Resources