Questions tagged [element]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
97 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 ...
user14370's user avatar
2 votes
1 answer
63 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 ...
James White's user avatar
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 ...
Matthias Redl-Mann's user avatar
1 vote
1 answer
30 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 ...
Sean Delaney's user avatar
1 vote
2 answers
385 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, ...
Piotr Pogorzelski's user avatar
13 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 ...
Ben Parizek's user avatar
  • 13.4k
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.
Alan Kimrey's user avatar
1 vote
1 answer
970 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, ...
Slowwie's user avatar
  • 235
1 vote
1 answer
332 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 ...
Laurence Cope's user avatar
1 vote
1 answer
163 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 ...
Aravona's user avatar
  • 111
3 votes
2 answers
894 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 ...
Greg Bowne's user avatar
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(); $...
biko's user avatar
  • 670
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:...
Alk's user avatar
  • 123
2 votes
0 answers
258 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 ...
user9975's user avatar
  • 534
1 vote
1 answer
63 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',...
user9975's user avatar
  • 534
1 vote
1 answer
43 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){ ...
Mark's user avatar
  • 731
1 vote
1 answer
345 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){ ...
Mark's user avatar
  • 731
1 vote
1 answer
48 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 ...
tim-pixeldeluxe's user avatar
1 vote
1 answer
387 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 = ...
Hector's user avatar
  • 187
1 vote
1 answer
174 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) { $...
Steven Grant's user avatar
  • 1,855
1 vote
1 answer
479 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 ...
Lazlo's user avatar
  • 185
1 vote
1 answer
489 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 ...
Shift2Design's user avatar
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( ...
Yuri Salimovskiy's user avatar
1 vote
1 answer
639 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(...
amof's user avatar
  • 151
1 vote
1 answer
473 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 ...
Visky Máté's user avatar
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 = ...
foamcow's user avatar
  • 2,019
1 vote
1 answer
853 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 ...
Stalinko's user avatar
  • 113
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, ...
amof's user avatar
  • 151
2 votes
2 answers
405 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);, ...
Matt Rose's user avatar
1 vote
1 answer
260 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'] }] ] }) %} ...
JamesNZ's user avatar
  • 937