In the following XML (using Xquery):
let $xml :=
(<list xml:id="first">
<item corresp="a"/>
</list>,
<list xml:id="second">
<item corresp="a"/>
<item corresp="b"/>
</list>,
<list xml:id="third">
<item corresp="b"/>
</list>,
<list xml:id="third">
<item corresp="c"/>
</list>,
<list xml:id="forth">
<item corresp="b"/>
<item corresp="c"/>
</list>)
I am trying to return <list> where #corresp has both a and b (this is a series that is dynamically constructed, from 1 - 15 items). However this:
return $xml[./item[#corresp=("a","b")]]
Returns
<list xml:id="first">
<item corresp="a"/>
</list>
<list xml:id="second">
<item corresp="a"/>
<item corresp="b"/>
</list>
<list xml:id="third">
<item corresp="b"/>
</list>
<list xml:id="forth">
<item corresp="b"/>
<item corresp="c"/>
</list>
When I am looking for this result
<list xml:id="second">
<item corresp="a"/>
<item corresp="b"/>
</list>
Additionally, the parameters contained in ("a","b")are dynamically constructed. Therefore I am trying to identify a solution that can take any number/combination of parameters in a series, anywhere between 1 and 15.
I'm not sure how to build the predicate to return the expected result.
Thanks in advance.
You can use every in your predicates, to specify that every key in your sequence must satisfies being the value of a corresp attribute, for a candidate list element.
The expression looks like: every $v in $seq satisfies $v, which returns true if the expression on the right-hand side of satisfies returns true for every value in $seq. It returns false otherwise.
So in your example:
<lists>
<list xml:id="first">
<item corresp="a"/>
</list>
<list xml:id="second">
<item corresp="a"/>
<item corresp="b"/>
</list>
<list xml:id="third">
<item corresp="b"/>
</list>
<list xml:id="third">
<item corresp="c"/>
</list>
<list xml:id="forth">
<item corresp="b"/>
<item corresp="c"/>
</list>
</lists>
/list[every $k in $keys satisfies item/#corresp = $k]
FYI, you also have any, that you use the same way as every, but which returns true if, you got it, the expression returns true for any item in the sequence.
Just change your request to
return $xml[item[#corresp="a"] and item[#corresp="b"]]
which will return the desired output
<list xml:id="second">
<item corresp="a"/>
<item corresp="b"/>
</list>
You have to make separate predicates for each <item> match.
I guess you were trying to simplify things too much, because you were selecting by an OR rather than an AND, because your predicate was checking if item[#corresp...] is contained in the set ("a","b").
Related
I tried to add a value in my UI form which is in xml type but I didn't succeed with the methods I found.
For example: this is my code
<field name="client_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">ClientId</item>
<item name="value" xsi:type="string" translate="true">Module\Core\DataObjects</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">smartbusiness</item>
<item name="dataScope" xsi:type="string">client_id</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
<item name="min_text_length" xsi:type="number">10</item>
<item name="max_text_length" xsi:type="number">250</item>
<item name="no-whitespace" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
And in my custom class I have that
<?php
namespace Module\Core\DataObjects;
use Module\Core\Model\SettingsFactory;
use Magento\Framework\App\ObjectManager;
class SettingsData
{
protected array $setting = [];
public function __construct()
{
$objectManager = ObjectManager::getInstance();
$modelFactory = $objectManager->get(SettingsFactory::class);
$collection = $modelFactory->create()->getCollection();
$collection->getSelect()->limit(1);
if ($collection->getSize()) {
$this->setting = $collection->getData()[0];
}
}
public function getData()
{
return $this->getClientId();
}
}
Any ideas how I could try?
I also tried to put class="Name of my class" in value, but it didn't work
I tried the above method + to attach the class name in the class attribute
Step 1:- Create a ui_form in
view/adminhtml/ui_component/sunarc_demo_type_form.xml
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/Ui/etc/ui_configuration.xsd">
<!--main part of the grid-->
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<!--Define where to find the data sources-->
<item name="provider" xsi:type="string">sunarc_demo_type_form.sunarc_demo_type_form_data_source</item>
<item name="deps" xsi:type="string">sunarc_demo_type_form.sunarc_demo_type_form_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">Add Dummy Data</item>
<item name="layout" xsi:type="array">
<item name="type" xsi:type="string">tabs</item>
</item>
<!-- <item name="buttons" xsi:type="array">
<item name="back" xsi:type="string">Sunarc\Enquiry\Block\Adminhtml\Type\Edit\BackButton</item>
<item name="reset" xsi:type="string">Sunarc\Enquiry\Block\Adminhtml\Type\Edit\ResetButton</item>
<item name="save" xsi:type="string">Sunarc\Enquiry\Block\Adminhtml\Type\Edit\SaveButton</item> -->
<!-- </item> -->
</argument>
<dataSource name="sunarc_demo_type_form_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">Sunarc\Demo\Model\Ui\DataProvider</argument>
<argument name="name" xsi:type="string">sunarc_demo_type_form_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">entity_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
<item name="submit_url" xsi:type="url" path="*/*/save"/>
</item>
</argument>
</dataSource>
<fieldset name="demo">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Add/Edit Type</item>
</item>
</argument>
<!-- This field represents form id and is hidden -->
<field name="entity_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">false</item>
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">type</item>
</item>
</argument>
</field>
<field name="demo_data">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string">Demo Data</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">input</item>
<item name="source" xsi:type="string">type</item>
</item>
</argument>
<settings>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
</validation>
</settings>
</field>
<!-- IF YOU WANT TO SHOW STATIC VALUE -->
<field name="text_example" formElement="input">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="default" xsi:type="string">SAMPLE TEXT HERE</item>
</item>
</argument>
<settings>
<label translate="true">SAMPLE TEXT</label>
<visible>true</visible>
<disabled>false</disabled>
<elementTmpl>ui/form/element/text</elementTmpl>
</settings>
</field>
</fieldset>
</form>
Step 2:- Create a DataSource File in Model/Ui/DataProvider.php
<?php
namespace Sunarc\Demo\Model\Ui;
use Sunarc\Demo\Model\ResourceModel\Demo\CollectionFactory;
class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
{
protected $loadedData;
/**
* #param string $name
* #param string $primaryFieldName
* #param string $requestFieldName
* #param CollectionFactory $typeCollectionFactory
* #param array $meta
* #param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
CollectionFactory $typeCollectionFactory,
array $meta = [],
array $data = []
) {
$this->collection = $typeCollectionFactory->create();
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
}
/**
* Get data
*
* #return array
*/
public function getData()
{
if (isset($this->loadedData)) {
return $this->loadedData;
}
$items = $this->collection->getItems();
foreach ($items as $item) {
$this->loadedData[$item->getData('entity_id')]['demo']['demo_data'] = $item->getData('demo_data');
}
return $this->loadedData;
// return [];
}
}
Click Here to check the input
I'm trying to make an anchor link in the product grid view.
I have tried this using UI component, below are the detailed view
xml code:
<column name="column_name" class="Vendor\Module\Ui\Component\Listing\Column\link">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Label</item>
<item name="sortOrder" xsi:type="number">50</item>
</item>
</argument>
</column>
datasource code:
$html = ''. __('Label').'';
$item[$this->getData('name')] = $html;
Getting html like this: Label
I want 'Label' with the anchor link.
I can not understand why the error
Could not save the brand: Notice: Array to string conversion in C:\OpenServer\domains\localhost\2016\mercury_61189_222_007\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php on line 228
on the idea of all done right, here is the code of the module
<field name="website_id_2">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Magento\Store\Model\ResourceModel\Website\Collection</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Website 2</item>
<item name="formElement" xsi:type="string">multiselect</item>
<item name="source" xsi:type="string">page</item>
<item name="dataScope" xsi:type="string">website_id_2</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
Can someone know the nuances?
I decided my question.
It was necessary for the save function to execute () to write 2 lines to preserve the array
$data['website_id_2']=implode(',',$data['website_id_2']);
$model->setData($data)->setId($this->getRequest()->getParam('id'));
In Magento 2 how can we add the WYSIWYG editor with the text area field with the form ui component xml file? To add the text area i am using the following code in xml file.
<field name="detail">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">true</item>
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">textarea</item>
<item name="source" xsi:type="string">sample_shop</item>
<item name="label" xsi:type="string">Detail</item>
</item>
</argument>
</field>
In your ui component form xml file add the field like this.
<field name="detail">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">wysiwyg</item>
<item name="source" xsi:type="string">sample_shop</item>
<item name="label" xsi:type="string">Detail</item>
<item name="template" xsi:type="string">ui/form/field</item>
<item name="wysiwyg" xsi:type="boolean">true</item>
<item name="dataScope" xsi:type="string">detail</item>
<item name="sortOrder" xsi:type="number">50</item>
<item name="rows" xsi:type="number">8</item>
</item>
</argument>
</field>
From Magento 2.2, below could work too. And it has better readability and usability.
<field name="content" formElement="wysiwyg">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">block</item>
</item>
</argument>
<settings>
<additionalClasses>
<class name="admin__field-wide">true</class>
</additionalClasses>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
</validation>
<label/>
<dataScope>content</dataScope>
</settings>
<formElements>
<wysiwyg>
<settings>
<wysiwyg>true</wysiwyg>
</settings>
</wysiwyg>
</formElements>
</field>
I need to find a specific string in a text, and then base on the position of the string, find a second string that is the closes to it (backwards) and print the information. I've got the following:
<tile x="143" y="43" z="7">
<item id="2656"/>
<item id="2111" count="5"/>
<item id="2194"/>
<item id="2205"/>
<item id="2400"/>
</tile>
<tile x="143" y="44" z="7">
<item id="2656"/>
<item id="2111" count="5"/>
<item id="2194"/>
<item id="2205"/>
</tile>
<tile x="143" y="45" z="7">
<item id="2656"/>
<item id="2111" count="5"/>
<item id="2194"/>
<item id="2205"/>
</tile>
<tile x="144" y="43" z="7">
<item id="2656"/>
<item id="2194"/>
<item id="2111" count="5"/>
<item id="2506" special_description="something something something (Arm:12) [Test]"/>
<item id="2194"/>
<item id="2216"/>
<item id="2400"/>
</tile>
<tile x="144" y="44" z="7">
<item id="2656"/>
<item id="2111" count="5"/>
<item id="2194"/>
<item id="2418"/>
<item id="2216"/>
<item id="2431"/>
</tile>
<tile x="144" y="45" z="7">
<item id="2656"/>
<item id="2658"/>
<item id="2111" count="5"/>
<item id="2506" special_description="something something (Arm:12) [Whatever]"/>
<item id="2194"/>
<item id="2216"/>
</tile>
<tile x="146" y="43" z="7">
<item id="1738"/>
<item id="1738"/>
<item id="1738"/>
<item id="2160" count="50"/>
<item id="2183"/>
<item id="2127"/>
<item id="2127"/>
<item id="2205"/>
<item id="2506"/>
<item id="2127"/>
</tile>
The text is all one line, I've split it in separate lines for it to be easier to look through. Originally it looks like this:
<tile x="143" y="43" z="7"><item id="2656"/><item id="2111" count="5"/><item id="2194"/><item id="2205"/><item id="2400"/></tile><tile x="143" y="44" z="7">...
Let's say I'm looking for 2 specific item id's - 2506 and 2418. I've found 2506 in the fourth tile block using grep, now I want to see what tile coordinates it has:
I've found this:
<item id="2506" special_description="something something something (Arm:12) [Test]"/>
and right above it I find this:
<tile x="144" y="43" z="7">
How would I be able to extract the tile information for all those, get the special description if it exists and generate a log?
Ideally it would look like this (but the output is not too important as long as I get all the information extracted):
2506:
144,43,7 | [Test]
144,45,7 | [Whatever]
146,43,7 |
2418:
144,44,7 |
Ideally if someone could get me a ready solution, it'd be much appreciated, but just a helpful pointer would be sufficient!
awk to the rescue!
this may get you started...
$ awk -F'\n' -v RS= '/id="2506"/{print $1}' file
<tile x="144" y="43" z="7">
<tile x="144" y="45" z="7">
<tile x="146" y="43" z="7">
It's better to write a script to do this. Here is the pseudo code:
for all lines in file do {
if line =~ /pattern1/ {
match1 = line
}
elsif line =~ /pattern2/ {
echo line, match1
}
}