Questions tagged [element]
The element tag has no usage guidance.
30 questions
1
vote
1
answer
171
views
Custom Element Type Documentation not working or confusing
Following the docs on the offical CraftCMS website i'm not able to get "Native Layout Elements" saved. My field body is always empty. Any idea what i'm missing here?
Relevant Part of Plugin ...
2
votes
1
answer
80
views
Registering an element source with EVENT_REGISTER_SOURCES for a specific site ID
Is it possible to register an element source for a specific site ID, while it not appearing in another?
I have a module which is currently registering element sources, however we are now looking to ...
1
vote
0
answers
32
views
Get query of autoinjection in case the entry is not found
Is there a way to get the element query which is/was executed by Craft to autoinject the corresponding entry into the template? (even if it fails)
I would like to catch it in case of a 404 to return a ...
1
vote
1
answer
36
views
Craft 3, Multi site setup - Update title for entry 1 site only
My setup:
Craft 3 installation with a multi-site setup. 3 languages, all enabled.
I have a custom plugin with a custom element type, FooBar that extends the Element class and a custom FooBar field ...
1
vote
2
answers
420
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,
...
14
votes
3
answers
2k
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 ...
1
vote
1
answer
71
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.
1
vote
1
answer
1k
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
1
answer
351
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
1
answer
178
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 ...
3
votes
2
answers
1k
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 ...
3
votes
2
answers
1k
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();
$...
1
vote
1
answer
1k
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
0
answers
265
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
1
answer
64
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
1
answer
47
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
1
answer
347
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
1
answer
57
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
1
answer
388
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
1
answer
181
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
1
answer
488
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
1
answer
507
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
2
answers
1k
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
1
answer
660
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
1
answer
482
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
1
answer
120
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
1
answer
872
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 ...
1
vote
1
answer
1k
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, ...
2
votes
2
answers
407
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);, ...
1
vote
1
answer
261
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'] }]
]
}) %}
...