![]() ![]() This condition is useful for when you want to run a reaction on a specific view mode like teaser. Now, before we finish up, the module comes with a second context condition called “Entity view mode”. The example I’ve shown in this tutorial is pretty basic but you get the idea behind the module. Set cache Time To Live Go to the Drupal admin panel Select Configuration > Performance Choose a Browser and proxy cache maximum age value Click the Save. If I select Article from the Tags field, the context rule will execute and I should see the “Active context: article_block” message. In my Tags vocabulary I have two terms: Article (term ID 1) and News (term ID 2).ģ. Enter “Test article” in the title field and select a term in the Tags field that has an ID of 1. Go to Content, “Add content” and Article.Ģ. Now that we’ve created a context rule using Entity field condition let’s test it out.ġ. ![]() The debug reaction will simply display a message saying that the reaction has been executed. ![]() From the Reactions section, select Debug from the and then click on Save. If you’re having trouble look at the get_field_value() method.Ħ. Also understand, that the Match option may not work with every field out there so make sure you test it out. This means that if a term with an ID of 1 is selected from the Tags field then the context rule will execute. And finally, use the Match option for when you want to match on a specific value. Then the “Empty value” is useful for when you want to check if a field is empty. The “All value” option is useful for when you want to check if a field has been filled out. A field’s status can be evaluated in three ways: “All value”, “Empty value” or Match. Now let’s take a quick detour and talk about the “Field status” option. Then in Field value enter in the term ID which you want to match on. From within the Entity field condition form select Node from Entity type, field_tags from Field name and Match from Field status.ĥ. In the Conditions section, click on the drop-down box and select Entity field.Ĥ. Enter in article_block into the Name field.ģ. Go to Structure, Context and click on Add.Ģ. Let’s first create a context rule that will be used to display a debug message.ġ. If you use Drush, run the following two commands:ĭrush dl context context_entity_-dev ctoolsĭrush en context_ui context_entity_field Create Context Rule Then install Context UI and Context entity field.įor this tutorial I’ll use the 7.x-1.x-dev branch. ![]() Head over to and download Context, Context entity field and Ctools. In this tutorial, we’ll use Context entity field to display a debug message only if a specific term is selected from the Tags field. Using Context entity field you can create a condition that checks the Tags field if a specific term has been selected. Let’s say you have a use-case where a block should only appear if an editor selects a tag like “Article”. It allows you to define a condition that checks the value of a field on an entity. Recently I’ve discovered a powerful module called Context entity field.
0 Comments
Leave a Reply. |