Questions tagged [element]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
2answers
85 views

Pass parameters to element query as array - in PHP

In Twig, we can do this like this: craft.entries({ id: 11, relatedTo: 22, }) But in PHP code, this does not work: \craft\elements\Entry::find( [ 'id' => 11, ...
11
votes
3answers
374 views

How do we distinguish between a 'New' and 'Updated' Live Entry using the craft\elements\Entry::EVENT_AFTER_SAVE event?

I can't decide if I'm missing something or this should be a bug. With the recent changes to Drafts/Revisions in Craft 3.7 it's not clear to me how to distinguish between New and Updated Entries using ...
2
votes
2answers
735 views

Craft 3 plugin - how to update entry with field of Entries type

Using PHP, I want to update a field of Entries type of an existing entry. Fields of type Text and Number will update with the following code: $entry = Entry::find()->id($entryId)->one(); $...
2
votes
2answers
231 views

How can I tell if a variable is an array or an entry/element query?

We have some components that are used to build pages, like normal, and some where we hydrate them with other data, so we are passing in arrays instead of entries. If something is essentially an ...
0
votes
0answers
17 views

How to validate a single field on an element?

I'm working on a migration which includes importing some phone numbers that will be stored in a Phone Number field. Some of the phone numbers are malformed, so I'm trying to validate the phone number ...
1
vote
1answer
26 views

Element API - lightswitch option to exclude an entry from a feed

I'm trying to exclude an entry based on the state of a lightswitch field in the entry itself. If true, exclude the entry from the feed, if false include the entry.
0
votes
0answers
23 views

Related elements Super Table

I try to get the digital products ,when an element is exist in the included elements . (the Digital product has a super table field which include elements) how it works in Craft ? it didn't work like ...
1
vote
1answer
69 views

Hook into Entry::EVENT_AFTER_SAVE when user saves it

I want to send a Mail to an admin, whenever a User of group ‚Cook‘ creates an Entry of Type ‚Recipe‘. For that I created an Event reacting on Entry::EVENT_AFTER_SAVE : Event::on( Entry::class, ...
1
vote
1answer
106 views

How to update stock on a product variant? Setting unknown property error

I am trying to update stock of product variants using a custom plugin on our Craft 3 eCommerce site (its a sync process with an external database). But I can't figure out how to update stock, I get an ...
1
vote
1answer
92 views

Users not fully deleting from the database

From the admin, if I delete a user they disappear from the admin list but not from the users database table. Looking through the code I can see UsersService.php has a function deleteUser which calls ...
1
vote
1answer
630 views

Select specific fields from query

I'm trying to get tags out of the underlying craft DB and serve it as a REST endpoint - however, I'm only interested in exposing the tag id and title, so my data should look like this: {id: 1, title:...
2
votes
0answers
197 views

change core element index pages

Is it possible to change core elements index pages -like entry index page- by plugin in PHP way, like extending their twig, using events, hooks and not manipulating DOM with Javascript? Currently ...
1
vote
1answer
54 views

How html title is generated in entry index page in CP

I am trying to find out how HTML title is generated in entry index page in Control Panel. i know it is generated in src/templates/_elements/element.html file by $this->hook('cp.elements.element',...
1
vote
1answer
30 views

Array from matrix fields without quotations

I am trying to create an array bodyBlocks by looping through all of my matrix fields called blockTextContent: $bodyBlocks = []; foreach ($entry->getFieldValue('pageBuilder')->all() as $block){ ...
1
vote
1answer
258 views

Matrix | Craft 3 Element API / Scout Plugin

I am trying to grab the contents a matrix field (Redactor). Here is the section of code I am struggling with: $bodyBlocks = []; foreach ($entry->getFieldValue('pageBuilder')->all() as $block){ ...
1
vote
1answer
33 views

Merge trashed element with existing one

Is there any way to merge trashed elements with an existing element? I'm creating a custom restore action so you can merge a trashed (commerce) Product with an existing one. The mergeElementsByIds ...
1
vote
1answer
565 views

Setting unknown property when trying to join table

I've successfully joined a table to the elements table, however I can't can't seem to add a property so I can use it? Getting the error Setting unknown property when trying to join table Entry::find(...
1
vote
1answer
224 views

Eager Loading Image Transforms In Plugin

The craft docs on eager loading show you how to eager load image transforms in twig. {% set entries = craft.entries({ with: [ ['coolImage', { withTransforms: ['transform'] }] ] }) %} ...
1
vote
1answer
328 views

API - Update Asset Volume

Im trying to figure out how to move asset(s) to a different volume. Also if I move it will that affect the entries that are using the asset? Here's what im using to target the asset: $resourceImage = ...
1
vote
1answer
131 views

Loop over table field in Element API plugin

How can I output the rows and values of a table field using the element api plugin? Where I have entries I do ... $industries = []; foreach ($entry->industries->all() as $industry) { $...
1
vote
1answer
434 views

What's the difference between a Component and a Model in Craft 3?

I'm trying to familiarize myself with the Craft architecture and I can't understand whether I should be extending craft\base\Component or craft\base\Model for my business logic models. Component seems ...
1
vote
1answer
376 views

Custom element index page (cp) sortable on dateCreated?

I have a plugin with custom elements that can be sorted on a handful of fields in my CP element index page. I can get the DATECREATED displaying correctly that Craft generates automatically but I ...
2
votes
2answers
954 views

Add custom attribute to standard element from plugin

Developing plugin for Craft 3, I want to add extra property to Assets (data being pulled from other table) I am able to pull in the data by extending element query: Event::on( ...
1
vote
1answer
868 views

Anyway to extend Craft Entry query search in Craft 3

I've had to manually do an SQL call to the get correct results but I was hoping there would be a tidier way of achieving this in Craft 3? $query = ( new Query() ) ->select('craft_content.title, ...
1
vote
1answer
385 views

How can I add programmatically a Tag after SAVE_ON event in case of Assets types

We have to update the Asset after the SAVE_ON event, and the Craft::$app->elements->saveElement($asset); Not seems to be working (it is getting timed out). So what is the best pratice to ...
1
vote
1answer
114 views

How to get related entry data using ElementCriteriaModel in a plugin

I am working on a custom plugin which gets some entry data using $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->order('postDate asc'); $criteria->dateUpdated = ...
1
vote
1answer
723 views

How to build complex Element Criteria?

How to fetch Elements with a complex DB query? E.g. with some nested AND/OR conditions or just apply two conditions to one field? For example my Elements have a field eventDate. I want to fetch all ...
2
votes
2answers
392 views

Using getCriteria with a custom element type

I've setup a custom element type for badges for a system I'm building, but I've run into some trouble trying to query for badges using craft()->elements->getCriteria(ElementType::Badges_Badge);, ...