I am following drupal docs to create a form, that stores XML. I only could find that, by default, it shows text-area field and user allowed text formats will be allowed.

I could not find anything that mentions XML, this is a required format for my project, anyone who understands Drupal is welcome for the suggestion.

I want to store and edit xml with drupal form.

Given form used by me:

$form['body'] = array(
  '#title' => 'Body',
  '#format' => 'full_html',
  '#default_value' => '',
);

Should I override default validator or write another form handler, please suggest

Comments

Jaypan’s picture

What is your project? It's hard to help without knowing what you're trying to do. You've only told us how you are attempting to do it - but we don't know what "it" is.

djassie’s picture

In my custom sidebar, I want to store the order as xml. 

I want to store this directly in Database, and require some edit, and update. So, xml will store "Order of links" in sidebar. 

Why you want to understand project? 

I just want to store xml in through text-area form - which will be parsed later through custom module, and xml value will be appended to the field with post_update hook. And edited by me as well. 

This is a detailed thing ~ and will complicate the question. So, I asked directly, how to store xml through "Form" - so that it can be edited. 

second note: xml will not be shown, just entered by admin/editor and used for parsing, and sidebar generation(order of sidebar links)

Anyway my project requires this

VM’s picture

he wanted to better understand the 'feature' you are building. 'project' likely a misnomer. To better understand the feature would allow for the offering of a method to satisfy the requirement. Unsure what is available for D8/9 but in D7 there was an XML field module, an XML form module and an XML formatted module. I don't think any have been ported to D8/D9.

djassie’s picture

Yes there is one module called "XML Field" in drupal 7, but I could not test as my project is in Drupal 9.

And there are also more Drupal 7 sites, not migrating to newer drupal versions(8, 9), so modules are not getiing written for Drupal 9.

But I don't want to lost into these mages. 

I just want to store xml(xml could be stored to database ~ there's no issue), but the issue is viewing through Drupal form so that it could be updated. 

Just think, sidebar along with the links and title, there's a sidebar component (some header component in sidebar), svg will be inserted in top of sidebar. All these could be stored in database directly ~ then there is no point of CMS. And I would have enter all command manually through "PHPMyAdmin", I want to update xml through Drupal CMS, that's all.

So, understand the use case. 

I just want Drupal support to edit and update xml, through form or any other way, but not directly by database(PHPMyAdmin Command).

Please Drupal devs, you understand the above, and have Drupal experience - please guide me a way.

What are the classes needed to be override or anything - please understand and help me, this is critical for my project

VM’s picture

being pushy won't get you anywhere except ignored. I mentioned the already existing modules because if they aren't D9 ready you can make them D9 ready. What you want to do isn't standard Drupal behavior whether you believe it to be a required part of a CMS or not.

if the intention is to migrate existing content into Drupal and map fields review core migration modules and modules such as feeds.module (in contrib).

Jaypan’s picture

I don't understand still. Are you trying to output an XML file?

VM’s picture

my take is the user wants to use a drupal content type to store XML which they can then edit directly in the content type as XML. Basically, an XML editor that using a drupal content type that then manipulates the theme layer based on the XML added to a content type.

djassie’s picture

I do not want to show xml to end-user, it for our use - to store the order of sidebar - 

XML: 

<sidebar>
<nav-head>Salamandar</nav-head>
<post><id>12</id><title>How to Pet</title></post>
<post><id>13</id><title>How to Feed</title></post>
<post><id>14</id><title>Which Cages</title></post>
<post><id>17</id><title>Types of Salamandar</title></post>
<post><id>19</id><title>Poisonus Breed</title></post>
<nav-header>Keeping Safe</nav-header>
<post><id>21</id><title>Keep out of Children</title></post>
<post><id>24</id><title>Keep out of Dogs</title></post>
<post><id>27</id><title>Keep out of Reptiles</title></post>
<post><id>34</id><title>Keep fungus free</title></post>
</sidebar>

Generated sidebar

<ul class="sidebar">
  <li class="nav-head">Salamandar</li>
  <li class="nav-item"><a class="nav-link" href="#">How to Pet</a></li>
  <li class="nav-item"><a class="nav-link active" href="#">How to Feed</a></li>
  <li class="nav-item"><a class="nav-link" href="#">Which Cages to use</a></li>
  <li class="nav-item"><a class="nav-link" href="#">Types of Salamandar</a></li>
  <li class="nav-item"><a class="nav-link" href="#">Poisonus Breed</a></li>
  <li class="nav-header">Keeping Safe</li>
  <li class="nav-item"><a class="nav-link" href="#">Keep salamandar out of children</a></li>
  <li class="nav-item"><a class="nav-link" href="#">Keep out of Dogs</a></li>
  <li class="nav-item"><a class="nav-link" href="#">Keep out of Reptiles</a></li>
</ul>

VM’s picture

typically this would be done via the core menu.module to build out a menu linked to content not directly via content and with XML.

djassie’s picture

The reality is - I have many more - long(large) list of articles to write about. Salamandar was just a simplified version of this. 

There are more than 250 types of animals as planned(however we do not write about 250 different variant of animals, we should keep a functionality, so that can be scaled. 

I want to keep this automatic, hence I was looking for xml structure. 

I never used "Menu" - kept everything simple. The nav-bar was used, and written simply, through (html, twig file). And nor want to have any dependency. 

The benifit of using xml, large of (Categories support), scalable, automatic. And menu will add more clutter - to manually set one by one, above it ~ there will be svg image inside the sidebar markup. 

Hence, I was requesting the know-how of the simplified version of my sidebar in xml. 

Jaypan’s picture

It seems you're trying to pigeonhole methodology you've used in other CMS into Drupal, rather than using Drupal methodology to achieve your goals. You're making more work for yourself in the end though, and it will be hard to find support, as few other people won't have experience in trying to use Drupal according to those methods.

djassie’s picture

After reading a few Drupal docs, one way would be to - create custom field with custom field formatter and another alternative is to define custom element. 

As document says - "Field formatter" just manages the view of the field, but I mentioned this as the name sounds, so maybe that could help. 

Could defining custom element help. 

We are determined to store xml, please devs help us - to find the right thing, to save our time and solve this quicky. 

Another update: could this Xss::filterAdmin help?