How to add widget to layout in Magento 2? - magento2

Is there a way to add widget to the layout xml? I know about the layout updates from the backend, but I wanted to know if there is a way to add widgets the same way as static blocks?

you can add widget via followings xml ,
<referenceContainer name="content.top">
<block class="Magento\Catalog\Block\Category\Widget\Link" name="demoBlock" template="widget/static_block/default.phtml">
<action method="setData">
<argument name="id_path" xsi:type="string">category/20</argument>
<argument name="title" xsi:type="string">Demo Category Title</argument>
<argument name="template" xsi:type="string">category/widget/link/link_inline.phtml</argument>
</action>
</block>
</referenceContainer>
you need to update followings
referenceContainer as per you needs
Block Class & Template (if you require to update the template for block)
arguments in setData

Related

How to override di.xml of core module in custom module Magento 2

I want to remove some portion from di.xml of vendor module. Below example of some portion that to be removed.
<type name="Magento\Braintree\Block\GooglePay\Shortcut\Button">
<arguments>
<argument name="data" xsi:type="array">
<item name="template" xsi:type="string">Magento_Braintree::googlepay/shortcut.phtml</item>
<item name="alias" xsi:type="string">braintree.googlepay.mini-cart</item>
<item name="button_id" xsi:type="string">braintree-googlepay-mini-cart</item>
</argument>
<argument name="payment" xsi:type="object">BraintreeGooglePay</argument>
</arguments>
</type>
How can I remove the it using override of di.xml in custom module.
Have you tried putting
<type name="Magento\Braintree\Block\GooglePay\Shortcut\Button">
<arguments>
</arguments>
</type>
Inside custom di.xml?
Then run php bin/magento setup:upgrade, so that dependencies are updated.
To remove the button completely, search for occurences of the block class and create own layout file(-s) in custom module (Vendor/Module/view/frontend/layout/{{THE_LAYOUT_NAME}}.xml) with following content:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="{{GOOGLE_PAY_BUTTON_BLOCK_NAME}}" remove="true"/>
</body>
</page>
EDIT: The button block name is defined within the layout files by the name attribute of <block> tag.
Thanks for sharing the possible options.
The solution that did work for me is to make the item inside argument tag to null.
In my scenario, I do not want this item in dependency injection. That works for me.
Below code added in custom module etc/frontend/di.xml
<type name="Magento\Braintree\Block\GooglePay\Shortcut\Button">
<arguments>
<argument name="data" xsi:type="array">
<item name="template" xsi:type="null" />
<item name="alias" xsi:type="null" />
<item name="button_id" xsi:type="null" />
</argument>
<argument name="payment" xsi:type="object">BraintreeGooglePay</argument>
</arguments>
</type>

Magento 2 - Copy price block to another location in product layout

I am trying to find a way to duplicate the price block so that it appears in two locations of the product page for specific products, by using the Layout Update XML field inside the design tab of the product edit page (Magento Admin).
I have successfully copied the price block by creating a modified layout XML file for specific products, for example:
theme_folder\Magento_Catalog\layout\catalog_product_view_id_178.xml
Inside this file I added the following in the required location:
<block class="Magento\Catalog\Pricing\Render" name="product.price.final.second.location" after="product.info.options.wrapper">
<arguments>
<argument name="price_render" xsi:type="string">product.price.render.default</argument>
<argument name="price_type_code" xsi:type="string">final_price</argument>
<argument name="zone" xsi:type="string">item_view</argument>
</arguments>
</block>
However there are too many products that use this modified layout and it would be easier to manage the product catalog if I could achieve the same thing just using the Layout Update XML field and entering a simple instruction like:
<copy element="product.price.final" destination="second.price.container">
Except there is no copy instruction, only a move instruction which is not what I want.
A different solution would be to have a way to select which layout XML to use from the product edit page, for example a yes/no attribute.
Is there a way to achieve this result?
I found the solution. The following XML inserted into the Layout Update XML field will copy the price block to a referenceBlock (or referenceContainer):
<referenceBlock name="my.reference.block">
<block class="Magento\Catalog\Pricing\Render" name="product.price.final.lower">
<arguments>
<argument name="price_render" xsi:type="string">product.price.render.default</argument>
<argument name="price_type_code" xsi:type="string">final_price</argument>
<argument name="zone" xsi:type="string">item_view</argument>
</arguments>
</block>
</referenceBlock>

Access 2013 form not updating when navigation button pressed

First time on site. Forgive me, I'm probably doing this wrong, but I have searched for 2 days and not found my answer.
After entering data in the Lead Maintenance form, clicking the Registrar tab runs the following macro:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<UserInterfaceMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application">
<UserInterfaceMacro For="navbtnRegistrar" Event="OnClick">
<Statements>
<Action Name="SetWarnings"/>
<Action Collapsed="true" Name="OpenQuery">
<Argument Name="QueryName">qryEnroll</Argument>
</Action>
<Action Name="OpenQuery">
<Argument Name="QueryName">qryLeadMainUpdateEnrollToTrue</Argument>
</Action>
<Action Name="SetWarnings">
<Argument Name="WarningsOn">Yes</Argument>
</Action>
<Action Name="OpenForm">
<Argument Name="FormName">frmStudentsData</Argument>
</Action>
<Action Name="CloseWindow">
<Argument Name="ObjectType">Form</Argument>
<Argument Name="ObjectName">frmStudentsData</Argument>
<Argument Name="Save">No</Argument>
</Action>
</Statements>
</UserInterfaceMacro>
</UserInterfaceMacros>
The new data is being appended to the table properly, however the New Student data form is not displaying the appended data. Any suggestions?
It looks like your Student Data Entry form is in "Data Entry" mode, so it will automatically only show a blank record for your users to fill out. You would need to turn off Data Entry mode, a property on the form itself and turn on the navigation bar that you already have on the Lead Maintenance form so that users can navigate between records.

Magento how to display block outside of body tag

My code :
<reference name="before_body_end">
<block type="test/test" template="test/test.phtml" name="test-test" />
</reference>
when i change to
<reference name="after_body_end">
<block type="test/test" template="test/test.phtml" name="test-test" />
</reference>
then it is not working. please help
It doesn't work because you are referencing ...well...nothing. The block with name after_body_end does not exist.
I will explain how to add it but first I want to make it clear that I don't approve of adding html outside the body tag. This may cause issues on some browsers.
First you need to create the block with name after_body_end.
For this edit the file app/design/frontend/{interface}/{theme}/layout/page.xml and look for this :
<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
<label>Page Bottom</label>
</block>
Right under that add the following.
<block type="core/text_list" name="after_body_end" as="after_body_end" translate="label">
<label>Page Unde the body tag</label>
</block>
Now your block exists. You just have to add it to your page. For this edit the following files all located in app/design/frontend/{interface}/{theme}/template/page/:
1column.phtml
2columns-left.phtml
2columns-right.phtml
3columns.phtml
empty.phtml
popup.phtml
print.phtml
For all these files add under the </body> line this:
<?php echo $this->getChildHtml('after_body_end') ?>
Clear the cache and enjoy.

Symfony2: Scope Widening Exception

I want to inject a form and formHandler service into my controller.
<services>
<service id="acme_core.image_controller" class="Acme\CoreBundle\Controller\ImageController">
<argument type="service" id="session" />
<argument type="service" id="acme_core.image.form" />
<argument type="service" id="acme_core.image.form.handler" />
<argument type="service" id="acme_core.image_manager.default" />
</service>
</services>
Scope Widening Injection detected: The definition "acme_core.image_controller" references the service "acme_core.image.form.handler" which belongs to a narrower scope. Generally, it is safer to either move "acme_core.image_controller" to scope "request" or alternatively rely on the provider pattern by injecting the container itself, and requesting the service "acme_core.image.form.handler" each time it is needed. In rare, special cases however that might not be necessary, then you can set the reference to strict=false to get rid of this error.
What does this mean concret?
What should I add tom my image_controller.xml?
Best Regards
You have to add scope="request" in your service tag e.g
<service id="acme_core.image_controller" class="Acme\CoreBundle\Controller\ImageController" scope="request">
For more info check this cookbook entry.