Hot answers tagged

4

You have 2 solutions: Implement your own Restore action, or Be lazy and reuse \craft\elements\actions I won't cover implementing you own action, let's be lazy! Declare the action To do this, you need to override the defineActions() method of your element's class: protected static function defineActions(string $source = null): array { $actions = parent::...


4

This functionality is comprised of multiple components – you need to build the interface, keep track of which visitor follows which events, potentially do something with that information and change up the display depending on the current time. The first thing you should do is clear up the requirements – what happens when someone follows an event? What ...


3

If you don't mind me rearranging your code a bit, I might go with something more like this... Event::on(Entry::class, Entry::EVENT_BEFORE_SAVE, static function (ModelEvent $event) { /** @var Entry $entry */ $entry = $event->sender; // Filter out all Drafts and Revisions if (ElementHelper::isDraftOrRevision($entry)) { Craft::$app-&...


2

You can't put PHP code into Twig, and there's no straightforward way to write custom DB queries in Twig. That's by design – Twig is a templating language, not meant for custom queries or processing. Instead, you should provide a service object with utitily methods that you can call from Twig. Depending on your use-case, you can accept parameters (for example,...


2

If you want multiple user accounts in Craft, then you'd need Craft Pro, regardless of the type of site you're trying to building on the front-end.


2

This is impossible (not only in Craft, but in general) because the fragment (hash, the part after the #) is only used on the client-side. This is by design, it's part of the spec that the fragment is never sent to the server. The server never knows about the fragment, so it can't do routing based on it. Using a fragment for routing is only possible if you ...


2

I have the base rate set up as a standard flat rate charge but wanted to know how to allow this toggle switch to remove the cost of shipping for that item. Yeh that lightswitch isn't well named. Unless you're using Commerce Lite you need to think about the cart as a whole not just a single product. In general, only coupon codes and adjusters can remove ...


2

A good place to put interfaces and tools that aren't super expansive or accessed very often is the Utilities section in the backend. Adding new utilities is very simple, you just add a class that implements the Utility interface (you can extend the base class, then you only have to provide a title and the HTML body). Then register that utility class using ...


1

If you have multiple sites, the ... button beside “Enabled for [Site Name]” will expand the setting so you can toggle the status for each site, including a switch for toggling the entry’s global status.


1

Yes, you can access the queue component using \Craft::$app->getQueue(). Keep in mind that this may return null or a non-compatible component depending on configuration, so make sure to check if the queue component is an instance of the craft\queue\QueueInterface. The default queue component (craft\queue\Queue) has all the methods you need to build your ...


1

I have fixed this issue with this code foreach ($home->infographics as $key => $infographicsValue) { $imageArr['width'] = $infographicsValue['width'] ? $infographicsValue['width'] : ""; $imageArr['height'] = $infographicsValue['height'] ? $infographicsValue['height'] : ""; $imageArr['alt'] = $infographicsValue['...


1

Edit: Previous answer was incorrect, see update below. What kind of field is infographics? How is it related to the infographicsImage field you're accessing in the loop? Either way, one of those is the assets field. Accessing an Assets field by handle returns an AssetQuery, not an Asset itself. To access the resulting assets, you need to execute the query ...


1

I fixed this in payment.twig by wrapping the payment form (id="paymentForm") in : {% if cart.shippingAddress and cart.shippingMethod %} //paypal and payment buttons <form id="paymentForm">...</form> {% else %} {% if not cart.shippingAddress %} <p>No shipping address selected.</p&...


1

I found a simple solution: exclude elements already having an id. Here's my final code: Event::on(Entry::class, Entry::EVENT_BEFORE_SAVE, static function (ModelEvent $event) { /** @var Entry $entry */ $entry = $event->sender; // Filter out existing elements if ($entry->id) { Craft::warning('Skipped existing element', 'Custom ...


1

The link is correct, it works fine here: Make sure that the domain is not blocked on the network level and there isn't anything weird going on with your DNS settings. Maybe clear your browser cache and restart your computer to clear the DNS cache.


1

The solution of the previous comment did workout for me, just notice that the blocks should be called like this: stc_XXX field_XXX


1

Matrix blocks are elements themselves, so the individual fields of a matrix block aren't available as properties on the entry. In the entry save hook, the only thing you can add errors to (that will be picked up by the interface) is the matrix field itself, using the matrix field's handle: use craft\elements\Entry; use craft\events\ModelEvent; use yii\base\...


1

The error likely indicates some language construct or syntax that is valid in PHP 7.4 but isn't in 7.2 – for example, indented heredoc strings only work in PHP 7.3 and above and would produce the Unexpected end of file error in previous versions. In general, make sure to test your plugin in your development environment against all PHP versions you intend to ...


1

As per the documentation, you can store your own plugins in the directory /config/redactor/plugins/. It isn't specifically mentioned, but plugins stored in the config directory take precedence before the bundled plugins. So you can overwrite any of the bundled plugins by copying them to that directory and modifying them there. This also allows you to put the ...


Only top voted, non community-wiki answers of a minimum length are eligible