I'm using Doctrine in Symfony 2 Application.
I have abstract class Object which is parent Entity for all objects in my applications (tasks, deals etc.).
* #ORM\Table(name="adm_object")
* #ORM\Entity(repositoryClass="Cloud\AdmBundle\Entity\Repository\ObjectRepository")
* #ORM\InheritanceType("JOINED")
* #ORM\DiscriminatorColumn(name="type", type="string")
*/
abstract class Object extends BaseEntity
{
For example task entity declaration now:
*
* #ORM\Table(name="crm_tasks")
* #ORM\Entity
*/
class Task extends Object
{
Now i want to make my own filter constraint in application using this function:
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
The problem is that when i try to get type of entity by using $targetEntity->getName() it gives me 'Object', not 'Task'... Is there possible to find out which 'object' it is ? Because i have 10 objects in my applications so I need to know which object I have now in my SQL Query to write proper filter...
Below var_dump of $targetEntity variable:
object(Doctrine\ORM\Mapping\ClassMetadata)[1412]
public 'name' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
public 'namespace' => string 'Cloud\AdmBundle\Entity' (length=22)
public 'rootEntityName' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
public 'customGeneratorDefinition' => null
public 'customRepositoryClassName' => string 'Cloud\AdmBundle\Entity\Repository\ObjectRepository' (length=50)
public 'isMappedSuperclass' => boolean false
public 'parentClasses' =>
array (size=0)
empty
public 'subClasses' =>
array (size=12)
0 => string 'Cloud\AdmBundle\Entity\Circle' (length=29)
1 => string 'Cloud\AdmBundle\Entity\Address' (length=30)
2 => string 'Cloud\AdmBundle\Entity\Note' (length=27)
3 => string 'Cloud\AdmBundle\Entity\Object1' (length=30)
4 => string 'Cloud\AdmBundle\Entity\Object2' (length=30)
5 => string 'Cloud\AdmBundle\Entity\Tag' (length=26)
6 => string 'Cloud\CalBundle\Entity\Event' (length=28)
7 => string 'Cloud\CrmBundle\Entity\Contact' (length=30)
8 => string 'Cloud\CrmBundle\Entity\Lead' (length=27)
9 => string 'Cloud\CrmBundle\Entity\ContactInformation' (length=41)
10 => string 'Cloud\CrmBundle\Entity\Deal' (length=27)
11 => string 'Cloud\CrmBundle\Entity\Task' (length=27)
public 'namedQueries' =>
array (size=0)
empty
public 'namedNativeQueries' =>
array (size=0)
empty
public 'sqlResultSetMappings' =>
array (size=0)
empty
public 'identifier' =>
array (size=1)
0 => string 'id' (length=2)
public 'inheritanceType' => int 2
public 'generatorType' => int 4
public 'fieldMappings' =>
array (size=4)
'id' =>
array (size=9)
'fieldName' => string 'id' (length=2)
'type' => string 'integer' (length=7)
'scale' => int 0
'length' => null
'unique' => boolean false
'nullable' => boolean false
'precision' => int 0
'columnName' => string 'id' (length=2)
'id' => boolean true
'add' =>
array (size=9)
'fieldName' => string 'add' (length=3)
'type' => string 'datetime' (length=8)
'scale' => int 0
'length' => null
'unique' => boolean false
'nullable' => boolean true
'precision' => int 0
'columnName' => string 'add' (length=3)
'quoted' => boolean true
'mod' =>
array (size=9)
'fieldName' => string 'mod' (length=3)
'type' => string 'datetime' (length=8)
'scale' => int 0
'length' => null
'unique' => boolean false
'nullable' => boolean true
'precision' => int 0
'columnName' => string 'mod' (length=3)
'quoted' => boolean true
'del' =>
array (size=9)
'fieldName' => string 'del' (length=3)
'type' => string 'datetime' (length=8)
'scale' => int 0
'length' => null
'unique' => boolean false
'nullable' => boolean true
'precision' => int 0
'columnName' => string 'del' (length=3)
'quoted' => boolean true
public 'fieldNames' =>
array (size=4)
'id' => string 'id' (length=2)
'add' => string 'add' (length=3)
'mod' => string 'mod' (length=3)
'del' => string 'del' (length=3)
public 'columnNames' =>
array (size=4)
'id' => string 'id' (length=2)
'add' => string 'add' (length=3)
'mod' => string 'mod' (length=3)
'del' => string 'del' (length=3)
public 'discriminatorValue' => string 'object' (length=6)
public 'discriminatorMap' =>
array (size=13)
'object' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'circle' => string 'Cloud\AdmBundle\Entity\Circle' (length=29)
'address' => string 'Cloud\AdmBundle\Entity\Address' (length=30)
'note' => string 'Cloud\AdmBundle\Entity\Note' (length=27)
'object1' => string 'Cloud\AdmBundle\Entity\Object1' (length=30)
'object2' => string 'Cloud\AdmBundle\Entity\Object2' (length=30)
'tag' => string 'Cloud\AdmBundle\Entity\Tag' (length=26)
'event' => string 'Cloud\CalBundle\Entity\Event' (length=28)
'contact' => string 'Cloud\CrmBundle\Entity\Contact' (length=30)
'lead' => string 'Cloud\CrmBundle\Entity\Lead' (length=27)
'contactinformation' => string 'Cloud\CrmBundle\Entity\ContactInformation' (length=41)
'deal' => string 'Cloud\CrmBundle\Entity\Deal' (length=27)
'task' => string 'Cloud\CrmBundle\Entity\Task' (length=27)
public 'discriminatorColumn' =>
array (size=5)
'name' => string 'type' (length=4)
'type' => string 'string' (length=6)
'length' => null
'columnDefinition' => null
'fieldName' => string 'type' (length=4)
public 'table' =>
array (size=2)
'name' => string 'adm_object' (length=10)
'options' =>
array (size=0)
empty
public 'lifecycleCallbacks' =>
array (size=0)
empty
public 'entityListeners' =>
array (size=1)
'postPersist' =>
array (size=1)
0 =>
array (size=2)
...
public 'associationMappings' =>
array (size=4)
'relation1' =>
array (size=15)
'fieldName' => string 'relation1' (length=9)
'mappedBy' => string 'relation1' (length=9)
'targetEntity' => string 'Cloud\AdmBundle\Entity\ObjectHasObject' (length=38)
'cascade' =>
array (size=0)
...
'orphanRemoval' => boolean false
'fetch' => int 2
'type' => int 4
'inversedBy' => null
'isOwningSide' => boolean false
'sourceEntity' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'isCascadeRemove' => boolean false
'isCascadePersist' => boolean false
'isCascadeRefresh' => boolean false
'isCascadeMerge' => boolean false
'isCascadeDetach' => boolean false
'relation2' =>
array (size=15)
'fieldName' => string 'relation2' (length=9)
'mappedBy' => string 'relation2' (length=9)
'targetEntity' => string 'Cloud\AdmBundle\Entity\ObjectHasObject' (length=38)
'cascade' =>
array (size=0)
...
'orphanRemoval' => boolean false
'fetch' => int 2
'type' => int 4
'inversedBy' => null
'isOwningSide' => boolean false
'sourceEntity' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'isCascadeRemove' => boolean false
'isCascadePersist' => boolean false
'isCascadeRefresh' => boolean false
'isCascadeMerge' => boolean false
'isCascadeDetach' => boolean false
'circle' =>
array (size=19)
'fieldName' => string 'circle' (length=6)
'joinColumns' =>
array (size=1)
...
'cascade' =>
array (size=0)
...
'inversedBy' => null
'targetEntity' => string 'Cloud\AdmBundle\Entity\Circle' (length=29)
'fetch' => int 2
'type' => int 2
'mappedBy' => null
'isOwningSide' => boolean true
'sourceEntity' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'isCascadeRemove' => boolean false
'isCascadePersist' => boolean false
'isCascadeRefresh' => boolean false
'isCascadeMerge' => boolean false
'isCascadeDetach' => boolean false
'sourceToTargetKeyColumns' =>
array (size=1)
...
'joinColumnFieldNames' =>
array (size=1)
...
'targetToSourceKeyColumns' =>
array (size=1)
...
'orphanRemoval' => boolean false
'user' =>
array (size=19)
'fieldName' => string 'user' (length=4)
'joinColumns' =>
array (size=1)
...
'cascade' =>
array (size=0)
...
'inversedBy' => null
'targetEntity' => string 'Cloud\AdmBundle\Entity\AdmUser' (length=30)
'fetch' => int 2
'type' => int 2
'mappedBy' => null
'isOwningSide' => boolean true
'sourceEntity' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'isCascadeRemove' => boolean false
'isCascadePersist' => boolean false
'isCascadeRefresh' => boolean false
'isCascadeMerge' => boolean false
'isCascadeDetach' => boolean false
'sourceToTargetKeyColumns' =>
array (size=1)
...
'joinColumnFieldNames' =>
array (size=1)
...
'targetToSourceKeyColumns' =>
array (size=1)
...
'orphanRemoval' => boolean false
public 'isIdentifierComposite' => boolean false
public 'containsForeignIdentifier' => boolean false
public 'idGenerator' =>
object(Doctrine\ORM\Id\IdentityGenerator)[1402]
private 'sequenceName' => null
public 'sequenceGeneratorDefinition' => null
public 'tableGeneratorDefinition' => null
public 'changeTrackingPolicy' => int 1
public 'isVersioned' => null
public 'versionField' => null
public 'reflClass' =>
object(ReflectionClass)[1390]
public 'name' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
public 'isReadOnly' => boolean false
protected 'namingStrategy' =>
object(Doctrine\ORM\Mapping\DefaultNamingStrategy)[381]
public 'reflFields' =>
array (size=8)
'id' =>
object(ReflectionProperty)[1401]
public 'name' => string 'id' (length=2)
public 'class' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'add' =>
object(ReflectionProperty)[1407]
public 'name' => string 'add' (length=3)
public 'class' => string 'Cloud\ApplicationBundle\Entity\BaseEntity' (length=41)
'mod' =>
object(ReflectionProperty)[1198]
public 'name' => string 'mod' (length=3)
public 'class' => string 'Cloud\ApplicationBundle\Entity\BaseEntity' (length=41)
'del' =>
object(ReflectionProperty)[1404]
public 'name' => string 'del' (length=3)
public 'class' => string 'Cloud\ApplicationBundle\Entity\BaseEntity' (length=41)
'relation1' =>
object(ReflectionProperty)[1408]
public 'name' => string 'relation1' (length=9)
public 'class' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'relation2' =>
object(ReflectionProperty)[1409]
public 'name' => string 'relation2' (length=9)
public 'class' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'circle' =>
object(ReflectionProperty)[1202]
public 'name' => string 'circle' (length=6)
public 'class' => string 'Cloud\ApplicationBundle\Entity\BaseEntity' (length=41)
'user' =>
object(ReflectionProperty)[1197]
public 'name' => string 'user' (length=4)
public 'class' => string 'Cloud\ApplicationBundle\Entity\BaseEntity' (length=41)
private '_prototype' (Doctrine\ORM\Mapping\ClassMetadataInfo) => null
public 'inheritanceMapping' =>
array (size=8)
'id' => null
'relation1' => null
'relation2' => null
'circle' => null
'user' => null
'add' => null
'mod' => null
'del' => null
Related
So if I have a group of fields on my Options page called product_tools and 3 fields within that of tool_link, tool_picture, and tool_name I am trying to get that out on a page with twig but it's not working for me? {{ options.product_tools.tool.name }} when I do a dump I get all the fields in an array just fine.
Here is the dump: {{ dump(options.product_tools) }}
C:\Users\WpDev\Local Sites\protoolsite\app\public\wp-content\plugins\timber-library\vendor\twig\twig\src\Extension\DebugExtension.php:70:
array (size=3)
'tool_link' => string 'https://www.dewalt.com/products/power-tools' (length=43)
'tool_picture' =>
array (size=24)
'ID' => int 307
'id' => int 307
'title' => string 'band-saw' (length=8)
'filename' => string 'band-saw.jpg' (length=12)
'filesize' => int 103647
'url' => string 'http://protoolsite.local/wp-content/uploads/2021/07/band-saw.jpg' (length=69)
'link' => string 'http://protoolsite.local/band-saw/' (length=39)
'alt' => string '' (length=0)
'author' => string '1' (length=1)
'description' => string '' (length=0)
'caption' => string '' (length=0)
'name' => string 'band-saw' (length=8)
'status' => string 'inherit' (length=7)
'uploaded_to' => int 0
'date' => string '2021-07-13 14:37:29' (length=19)
'modified' => string '2021-07-13 14:37:29' (length=19)
'menu_order' => int 0
'mime_type' => string 'image/jpeg' (length=10)
'type' => string 'image' (length=5)
'subtype' => string 'jpeg' (length=4)
'icon' => string 'http://protoolsite.local/wp-includes/images/media/default.png' (length=66)
'width' => int 1000
'height' => int 1000
'sizes' =>
array (size=18)
'thumbnail' => string 'http://protoolsite.local/wp-content/uploads/2021/07/band-saw-150x150.jpg' (length=77)
'thumbnail-width' => int 150
'thumbnail-height' => int 150
'medium' => string 'http://protoolsite.local/wp-content/uploads/2021/07/band-saw-300x300.jpg' (length=77)
'medium-width' => int 300
'medium-height' => int 300
'medium_large' => string 'http://protoolsite.local/wp-content/uploads/2021/07/band-saw-768x768.jpg' (length=77)
'medium_large-width' => int 768
'medium_large-height' => int 768
'large' => string 'http://protoolsite.local/wp-content/uploads/2021/07/band-saw.jpg' (length=69)
'large-width' => int 1000
'large-height' => int 1000
'1536x1536' => string 'http://protoolsite.local/wp-content/uploads/2021/07/band-saw.jpg' (length=69)
'1536x1536-width' => int 1000
'1536x1536-height' => int 1000
'2048x2048' => string 'http://protoolsite.local/wp-content/uploads/2021/07/band-saw.jpg' (length=69)
'2048x2048-width' => int 1000
'2048x2048-height' => int 1000
'tool_name' => string 'Dewalt Bandsaw' (length=14)
I have registered a meta box inside posts and pages with a check box to prevent that post/page from being shown in the search results. Once the user checks on that check box and hits save/update the post, a meta key called _dont_show_in_search_results with value POST_ID will be saved into the database associated with that post.
Inside pre_get_posts action, I'm doing the following:
function exclude_posts_from_search( $query ){
if($query->is_main_query() && is_search() ){
$query->set('meta_query', array(array("key"=>"_dont_show_in_search_results", "compare"=>"NOT EXISTS")));
}
}
add_action('pre_get_posts','exclude_posts_from_search');
It used to work in the past, but not sure what happened for that query as now it doesn't show any results on the search page!
The WordPress version I'm using is 5.2.3. Seems this issue has been reported many times as bugs, here and here.
If I tried to print the query, it shows like this:
object(WP_Query)[566]
public 'query' =>
array (size=1)
's' => string 'searchTerm' (length=10)
public 'query_vars' =>
array (size=53)
's' => string 'searchTerm' (length=10)
'error' => string '' (length=0)
'm' => string '' (length=0)
'p' => int 0
'post_parent' => string '' (length=0)
'subpost' => string '' (length=0)
'subpost_id' => string '' (length=0)
'attachment' => string '' (length=0)
'attachment_id' => int 0
'name' => string '' (length=0)
'static' => string '' (length=0)
'pagename' => string '' (length=0)
'page_id' => int 0
'second' => string '' (length=0)
'minute' => string '' (length=0)
'hour' => string '' (length=0)
'day' => int 0
'monthnum' => int 0
'year' => int 0
'w' => int 0
'category_name' => string '' (length=0)
'tag' => string '' (length=0)
'cat' => string '' (length=0)
'tag_id' => string '' (length=0)
'author' => string '' (length=0)
'author_name' => string '' (length=0)
'feed' => string '' (length=0)
'tb' => string '' (length=0)
'paged' => int 0
'meta_key' => string '' (length=0)
'meta_value' => string '' (length=0)
'preview' => string '' (length=0)
'sentence' => string '' (length=0)
'title' => string '' (length=0)
'fields' => string '' (length=0)
'menu_order' => string '' (length=0)
'embed' => string '' (length=0)
'category__in' =>
array (size=0)
empty
'category__not_in' =>
array (size=0)
empty
'category__and' =>
array (size=0)
empty
'post__in' =>
array (size=0)
empty
'post__not_in' =>
array (size=0)
empty
'post_name__in' =>
array (size=0)
empty
'tag__in' =>
array (size=0)
empty
'tag__not_in' =>
array (size=0)
empty
'tag__and' =>
array (size=0)
empty
'tag_slug__in' =>
array (size=0)
empty
'tag_slug__and' =>
array (size=0)
empty
'post_parent__in' =>
array (size=0)
empty
'post_parent__not_in' =>
array (size=0)
empty
'author__in' =>
array (size=0)
empty
'author__not_in' =>
array (size=0)
empty
'meta_query' =>
array (size=1)
0 =>
array (size=2)
'key' => string '_dont_show_in_search_results' (length=28)
'compare' => string 'NOT EXISTS' (length=10)
public 'tax_query' =>
object(WP_Tax_Query)[1650]
public 'queries' =>
array (size=0)
empty
public 'relation' => string 'AND' (length=3)
protected 'table_aliases' =>
array (size=0)
empty
public 'queried_terms' =>
array (size=0)
empty
public 'primary_table' => null
public 'primary_id_column' => null
public 'meta_query' => boolean false
public 'date_query' => boolean false
public 'post_count' => int 0
public 'current_post' => int -1
public 'in_the_loop' => boolean false
public 'comment_count' => int 0
public 'current_comment' => int -1
public 'found_posts' => int 0
public 'max_num_pages' => int 0
public 'max_num_comment_pages' => int 0
public 'is_single' => boolean false
public 'is_preview' => boolean false
public 'is_page' => boolean false
public 'is_archive' => boolean false
public 'is_date' => boolean false
public 'is_year' => boolean false
public 'is_month' => boolean false
public 'is_day' => boolean false
public 'is_time' => boolean false
public 'is_author' => boolean false
public 'is_category' => boolean false
public 'is_tag' => boolean false
public 'is_tax' => boolean false
public 'is_search' => boolean true
public 'is_feed' => boolean false
public 'is_comment_feed' => boolean false
public 'is_trackback' => boolean false
public 'is_home' => boolean false
public 'is_privacy_policy' => boolean false
public 'is_404' => boolean false
public 'is_embed' => boolean false
public 'is_paged' => boolean false
public 'is_admin' => boolean false
public 'is_attachment' => boolean false
public 'is_singular' => boolean false
public 'is_robots' => boolean false
public 'is_posts_page' => boolean false
public 'is_post_type_archive' => boolean false
private 'query_vars_hash' => string '0d61505a07baa4860f1831a27ad01416' (length=32)
private 'query_vars_changed' => boolean false
public 'thumbnails_cached' => boolean false
private 'stopwords' => null
private 'compat_fields' =>
array (size=2)
0 => string 'query_vars_hash' (length=15)
1 => string 'query_vars_changed' (length=18)
private 'compat_methods' =>
array (size=2)
0 => string 'init_query_flags' (length=16)
1 => string 'parse_tax_query' (length=15)
It was a plugin conflict with Cornerstone new search functionality.
How can i have access to subfields of a paragraph field.
For my carousel, i made a "hero image carousel" paragraph, then for the fields, i made another subparagraph "hero image carousel fields" which i assigned into the first one. that let makes me multiple slides and it works perfectly on backend.
Now i want to style it inside the twig templates.
I'm able to acces directly into the first, second etc. subfields like that:
content.field_hero_image_c_fields.0['#paragraph'].field_hero_image_c_content
But i need to have that in a loop. The issue now is, when i do something like:
{% for item in content.field_hero_image_c_fields %}
{{ item }}
{% endfor %}
It does get my fields, but also other default fields like uuid, field_name and so on.
Here the dump of content:
array (size=2)
'field_hero_image_c_fields' =>
array (size=18)
'#theme' => string 'field' (length=5)
'#title' => string 'Hero Image Karussell Felder' (length=27)
'#label_display' => string 'hidden' (length=6)
'#view_mode' => string 'default' (length=7)
'#language' => string 'de' (length=2)
'#field_name' => string 'field_hero_image_c_fields' (length=25)
'#field_type' => string 'entity_reference_revisions' (length=26)
'#field_translatable' => boolean false
'#entity_type' => string 'paragraph' (length=9)
'#bundle' => string 'hero_image_carousel' (length=19)
'#object' =>
object(Drupal\paragraphs\Entity\Paragraph)[1484]
protected 'unserializedBehaviorSettings' => null
protected 'values' =>
array (size=21)
...
protected 'fields' =>
array (size=6)
...
protected 'fieldDefinitions' =>
array (size=19)
...
protected 'languages' =>
array (size=4)
...
protected 'langcodeKey' => string 'langcode' (length=8)
protected 'defaultLangcodeKey' => string 'default_langcode' (length=16)
protected 'activeLangcode' => string 'x-default' (length=9)
protected 'defaultLangcode' => string 'de' (length=2)
protected 'translations' =>
array (size=1)
...
protected 'translationInitialize' => boolean false
protected 'newRevision' => boolean false
protected 'isDefaultRevision' => string '1' (length=1)
protected 'entityKeys' =>
array (size=4)
...
protected 'translatableEntityKeys' =>
array (size=2)
...
protected 'validated' => boolean false
protected 'validationRequired' => boolean false
protected 'loadedRevisionId' => string '247' (length=3)
protected 'entityTypeId' => string 'paragraph' (length=9)
protected 'enforceIsNew' => null
protected 'typedData' =>
object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter)[1554]
...
protected 'cacheContexts' =>
array (size=0)
...
protected 'cacheTags' =>
array (size=0)
...
protected 'cacheMaxAge' => int -1
protected '_serviceIds' =>
array (size=0)
...
protected 'needsSave' => boolean false
'#items' =>
object(Drupal\entity_reference_revisions\EntityReferenceRevisionsFieldItemList)[870]
protected 'list' =>
array (size=2)
...
protected 'langcode' => string 'de' (length=2)
protected 'definition' =>
object(Drupal\field\Entity\FieldConfig)[1544]
...
protected 'name' => string 'field_hero_image_c_fields' (length=25)
protected 'parent' =>
object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter)[1554]
...
protected 'stringTranslation' => null
protected 'typedDataManager' =>
object(Drupal\Core\TypedData\TypedDataManager)[765]
...
'#formatter' => string 'entity_reference_revisions_entity_view' (length=38)
'#is_multiple' => boolean true
0 =>
array (size=6)
'#paragraph' =>
object(Drupal\paragraphs\Entity\Paragraph)[2440]
...
'#view_mode' => string 'default' (length=7)
'#cache' =>
array (size=3)
...
'#theme' => string 'paragraph' (length=9)
'#weight' => int 0
'#pre_render' =>
array (size=1)
...
1 =>
array (size=6)
'#paragraph' =>
object(Drupal\paragraphs\Entity\Paragraph)[2264]
...
'#view_mode' => string 'default' (length=7)
'#cache' =>
array (size=3)
...
'#theme' => string 'paragraph' (length=9)
'#weight' => int 0
'#pre_render' =>
array (size=1)
...
'#cache' =>
array (size=3)
'contexts' =>
array (size=0)
...
'tags' =>
array (size=0)
...
'max-age' => int -1
'#weight' => int 1
'field_hero_image_c_scroll_link' =>
array (size=17)
'#theme' => string 'field' (length=5)
'#title' => string 'Scroll Link' (length=11)
'#label_display' => string 'hidden' (length=6)
'#view_mode' => string 'default' (length=7)
'#language' => string 'de' (length=2)
'#field_name' => string 'field_hero_image_c_scroll_link' (length=30)
'#field_type' => string 'link' (length=4)
'#field_translatable' => boolean false
'#entity_type' => string 'paragraph' (length=9)
'#bundle' => string 'hero_image_carousel' (length=19)
'#object' =>
object(Drupal\paragraphs\Entity\Paragraph)[1484]
protected 'unserializedBehaviorSettings' => null
protected 'values' =>
array (size=21)
...
protected 'fields' =>
array (size=6)
...
protected 'fieldDefinitions' =>
array (size=19)
...
protected 'languages' =>
array (size=4)
...
protected 'langcodeKey' => string 'langcode' (length=8)
protected 'defaultLangcodeKey' => string 'default_langcode' (length=16)
protected 'activeLangcode' => string 'x-default' (length=9)
protected 'defaultLangcode' => string 'de' (length=2)
protected 'translations' =>
array (size=1)
...
protected 'translationInitialize' => boolean false
protected 'newRevision' => boolean false
protected 'isDefaultRevision' => string '1' (length=1)
protected 'entityKeys' =>
array (size=4)
...
protected 'translatableEntityKeys' =>
array (size=2)
...
protected 'validated' => boolean false
protected 'validationRequired' => boolean false
protected 'loadedRevisionId' => string '247' (length=3)
protected 'entityTypeId' => string 'paragraph' (length=9)
protected 'enforceIsNew' => null
protected 'typedData' =>
object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter)[1554]
...
protected 'cacheContexts' =>
array (size=0)
...
protected 'cacheTags' =>
array (size=0)
...
protected 'cacheMaxAge' => int -1
protected '_serviceIds' =>
array (size=0)
...
protected 'needsSave' => boolean false
'#items' =>
object(Drupal\Core\Field\FieldItemList)[2265]
protected 'list' =>
array (size=1)
...
protected 'langcode' => string 'de' (length=2)
protected 'definition' =>
object(Drupal\field\Entity\FieldConfig)[1546]
...
protected 'name' => string 'field_hero_image_c_scroll_link' (length=30)
protected 'parent' =>
object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter)[1554]
...
protected 'stringTranslation' => null
protected 'typedDataManager' =>
object(Drupal\Core\TypedData\TypedDataManager)[765]
...
'#formatter' => string 'link' (length=4)
'#is_multiple' => boolean false
0 =>
array (size=4)
'#type' => string 'link' (length=4)
'#title' => string 'Die entdecken!' (length=27)
'#options' =>
array (size=0)
...
'#url' =>
object(Drupal\Core\Url)[2421]
...
'#cache' =>
array (size=3)
'contexts' =>
array (size=0)
...
'tags' =>
array (size=0)
...
'max-age' => int -1
'#weight' => int 2
And here the dump of
How can i access and make the loop only for the fields i need?
Thanks for any advice!
This approach worked for me
{% for item in content['#node'].field_myparagraphfield_items %}
....
<img class="carousel-image-fullsize" src="{{ file_url( item.entity.field_picture_item_image_main[0].entity.uri.value | image_style("my_carousel_image_style") )}}">
....
{% endfor %}
the fields in the paragraph will be found like item.entity.field_picture_item_image_main inside the for loop. Not the easiest thing to figure out!
I have a custom CPT named restaurant and I need to create url in different languages using WPML, like:
http://example.com/restaurants/latvia/riga/restaurant-name
http://example.com/it/ristoranti/lettonia/riga/nome-ristorante
In the main language it works, no problem at all.
The problem is with the it lang, if I visit the link I get 404 page.
If I add var_dump to the $query in pre_get_posts I get:
object(WP_Query)[2049]
public 'query' =>
array (size=1)
'attachment' => string 'steiku-haoss' (length=12)
public 'query_vars' =>
array (size=53)
'attachment' => string 'steiku-haoss' (length=12)
'error' => string '' (length=0)
'm' => string '' (length=0)
'p' => int 0
'post_parent' => string '' (length=0)
'subpost' => string '' (length=0)
'subpost_id' => string '' (length=0)
'attachment_id' => int 0
'name' => string '' (length=0)
'static' => string '' (length=0)
'pagename' => string '' (length=0)
'page_id' => int 0
'second' => string '' (length=0)
'minute' => string '' (length=0)
'hour' => string '' (length=0)
'day' => int 0
'monthnum' => int 0
'year' => int 0
'w' => int 0
'category_name' => string '' (length=0)
'tag' => string '' (length=0)
'cat' => string '' (length=0)
'tag_id' => string '' (length=0)
'author' => string '' (length=0)
'author_name' => string '' (length=0)
'feed' => string '' (length=0)
'tb' => string '' (length=0)
'paged' => int 0
'meta_key' => string '' (length=0)
'meta_value' => string '' (length=0)
'preview' => string '' (length=0)
's' => string '' (length=0)
'sentence' => string '' (length=0)
'title' => string '' (length=0)
'fields' => string '' (length=0)
'menu_order' => string '' (length=0)
'embed' => string '' (length=0)
'category__in' =>
array (size=0)
empty
'category__not_in' =>
array (size=0)
empty
'category__and' =>
array (size=0)
empty
'post__in' =>
array (size=0)
empty
'post__not_in' =>
array (size=0)
empty
'post_name__in' =>
array (size=0)
empty
'tag__in' =>
array (size=0)
empty
'tag__not_in' =>
array (size=0)
empty
'tag__and' =>
array (size=0)
empty
'tag_slug__in' =>
array (size=0)
empty
'tag_slug__and' =>
array (size=0)
empty
'post_parent__in' =>
array (size=0)
empty
'post_parent__not_in' =>
array (size=0)
empty
'author__in' =>
array (size=0)
empty
'author__not_in' =>
array (size=0)
empty
'meta_query' =>
array (size=0)
empty
public 'tax_query' => null
public 'meta_query' => boolean false
public 'date_query' => boolean false
public 'post_count' => int 0
public 'current_post' => int -1
public 'in_the_loop' => boolean false
public 'comment_count' => int 0
public 'current_comment' => int -1
public 'found_posts' => int 0
public 'max_num_pages' => int 0
public 'max_num_comment_pages' => int 0
public 'is_single' => boolean true
public 'is_preview' => boolean false
public 'is_page' => boolean false
public 'is_archive' => boolean false
public 'is_date' => boolean false
public 'is_year' => boolean false
public 'is_month' => boolean false
public 'is_day' => boolean false
public 'is_time' => boolean false
public 'is_author' => boolean false
public 'is_category' => boolean false
public 'is_tag' => boolean false
public 'is_tax' => boolean false
public 'is_search' => boolean false
public 'is_feed' => boolean false
public 'is_comment_feed' => boolean false
public 'is_trackback' => boolean false
public 'is_home' => boolean false
public 'is_404' => boolean false
public 'is_embed' => boolean false
public 'is_paged' => boolean false
public 'is_admin' => boolean false
public 'is_attachment' => boolean true
public 'is_singular' => boolean true
public 'is_robots' => boolean false
public 'is_posts_page' => boolean false
public 'is_post_type_archive' => boolean false
private 'query_vars_hash' => string '5215071224e026852fe2fe893457f985' (length=32)
private 'query_vars_changed' => boolean false
public 'thumbnails_cached' => boolean false
private 'stopwords' => null
private 'compat_fields' =>
array (size=2)
0 => string 'query_vars_hash' (length=15)
1 => string 'query_vars_changed' (length=18)
private 'compat_methods' =>
array (size=2)
0 => string 'init_query_flags' (length=16)
1 => string 'parse_tax_query' (length=15)
As you can see it is queried like attachment.
I have also created a custom rewrite_rule but is ignored, I also tryed to hard-code the value but WP will ignore it anyway:
add_rewrite_rule($lang_code . '/' . $pt_translated . '/lettonia/riga/steiku-haoss/?$',
'index.php?&post_type=' . $pt_original . '&mlt_location=lettonia&name=$matches[3]', 'top');
This is my reg_exp: it/ristoranti/.+?/[^/]+/([^/]+)/?$
How is this possibile?
Edit
I use WPML
when I'm adding fields of my entity in Symfony forms, the entity annotations are mapped and based on this Symfony guess if my field can be nullable or not, so far so good, such as this dump:
public 'fieldMappings' =>
array (size=5)
'acl' =>
array (size=9)
'fieldName' => string 'acl' (length=3)
'type' => string 'smallint' (length=8)
'scale' => int 0
'length' => null
'unique' => boolean false
'nullable' => boolean true
'precision' => int 0
'options' =>
array (size=2)
...
'columnName' => string 'acl' (length=3)
'id' =>
array (size=10)
'fieldName' => string 'id' (length=2)
'type' => string 'integer' (length=7)
'scale' => int 0
'length' => null
'unique' => boolean true
'nullable' => boolean false
'precision' => int 0
'options' =>
array (size=2)
...
'columnName' => string 'id' (length=2)
'id' => boolean true
But if I have associating fields (foreign keys), Symfony has a different mapping structure and doesn't guess if the field can be nullable or not, such as this dump:
public 'associationMappings' =>
array (size=3)
'userObj' =>
array (size=19)
'fieldName' => string 'userObj' (length=7)
'joinColumns' =>
array (size=1)
...
'cascade' =>
array (size=0)
...
'inversedBy' => null
'targetEntity' => string 'AdminBundle\Entity\User' (length=23)
'fetch' => int 2
'type' => int 2
'mappedBy' => null
'isOwningSide' => boolean true
'sourceEntity' => string 'AdminBundle\Entity\UserAcl' (length=26)
'isCascadeRemove' => boolean false
'isCascadePersist' => boolean false
'isCascadeRefresh' => boolean false
'isCascadeMerge' => boolean false
'isCascadeDetach' => boolean false
'sourceToTargetKeyColumns' =>
array (size=1)
...
'joinColumnFieldNames' =>
array (size=1)
...
'targetToSourceKeyColumns' =>
array (size=1)
...
'orphanRemoval' => boolean false
'storeObj' =>
array (size=19)
'fieldName' => string 'storeObj' (length=8)
'joinColumns' =>
array (size=1)
...
'cascade' =>
array (size=0)
...
'inversedBy' => null
'targetEntity' => string 'AdminBundle\Entity\Store' (length=24)
'fetch' => int 2
'type' => int 2
'mappedBy' => null
'isOwningSide' => boolean true
'sourceEntity' => string 'AdminBundle\Entity\UserAcl' (length=26)
'isCascadeRemove' => boolean false
'isCascadePersist' => boolean false
'isCascadeRefresh' => boolean false
'isCascadeMerge' => boolean false
'isCascadeDetach' => boolean false
'sourceToTargetKeyColumns' =>
array (size=1)
...
'joinColumnFieldNames' =>
array (size=1)
...
'targetToSourceKeyColumns' =>
array (size=1)
...
'orphanRemoval' => boolean false
So in these cases the required attribute needs to be configured manually, otherwise it will be true (is the default value by Symfony forms).
Anyone know how Symfony can guess the required attribute in these cases?
My entity have the following annotations:
/**
* #ORM\ManyToOne(targetEntity="User")
* #ORM\JoinColumn(name="fk_user", referencedColumnName="id", nullable=false, unique=false, onDelete="CASCADE")
*/
private $userObj;
/**
* #ORM\ManyToOne(targetEntity="Store")
* #ORM\JoinColumn(name="fk_store", referencedColumnName="id", nullable=false, unique=false, onDelete="CASCADE")
*/
private $storeObj;
You can create a TypeGuesser service. That's a hell of a lot of work, though, so why not manually set the fields once and be done with it?