Answers.Body: <p>Yes this is correct. The best documentation you can find is the source code, so looking at it is usually the way to go. Craft stores all relations with an <strong>array</strong> of element ids.</p>
  
  <p>When you have a <code>BaseRelationField</code> in your elements field layout you'll store the value - even if it's a single value - like</p>
  
  <pre><code>$element-&gt;setFieldValue('day', [1]); //&lt;- note, always pass an array
  </code></pre>
  
  <p>(or the faster variant) </p>
  
  <pre><code>$fieldsLocation = Craft::$app-&gt;getRequest()-&gt;getParam('fieldsLocation', 'fields');
  $element-&gt;setFieldValuesFromRequest($fieldsLocation);
  </code></pre>
  
  <p>If you don't use a field layout and store your relations in a custom table/column you'll have to find a way that fits your requirements</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-10T08:50:51.377Z
Answers.LastActivityDate: 2018-04-10T08:50:51.377Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm currently working on creating a full-sized Edit Page for my own Element Type.  </p>
  
  <p>I created a <code>elementSelectField</code> and wanted to know if you guys have some advise or good articles to read on that matter. Right now I'm crawling my way through the craft code for reverence and i am not sure if I'm doing this correctly :)</p>
  
  <pre><code>{% set section = craft.app.sections.getSectionByHandle('days') %}
  {% set elementType = craft.app.elements.getElementTypeByRefHandle('Entry') %}
  
  {{ forms.elementSelectField({
          label: 'Day'|t('app'),
          instructions: 'The day the cookie belongs to'|t('app'),
          id: 'day',
          name: 'day',
          elementType: elementType,
          selectionLabel: "Choose a day"|t('app'),
          sources: ['section:'~section.id],
          criteria: '',
          elements: elementType,
          viewMode: 'list',
          limit: 1,
      })
  }}
  </code></pre>
  
  <p>I think this is Ok? Sending the form to my controller and dumping it there, the <code>selectfield</code>'s value array contains only the choosen entry's id.</p>
  
Tags: <plugin-development><sections><elementtype>
Title: Element Type: Edit Page fields
ThreadText: # Element Type: Edit Page fields
  
  (Asked by: username_0 on 2018-04-10)
  
  I'm currently working on creating a full-sized Edit Page for my own Element Type.
  
  I created a `elementSelectField` and wanted to know if you guys have some advise or good articles to read on that matter. Right now I'm crawling my way through the craft code for reverence and i am not sure if I'm doing this correctly :)
  
  ```
  {% set section = craft.app.sections.getSectionByHandle('days') %}
  {% set elementType = craft.app.elements.getElementTypeByRefHandle('Entry') %}
  
  {{ forms.elementSelectField({
          label: 'Day'|t('app'),
          instructions: 'The day the cookie belongs to'|t('app'),
          id: 'day',
          name: 'day',
          elementType: elementType,
          selectionLabel: "Choose a day"|t('app'),
          sources: ['section:'~section.id],
          criteria: '',
          elements: elementType,
          viewMode: 'list',
          limit: 1,
      })
  }}
  
  ```
  
  I think this is Ok? Sending the form to my controller and dumping it there, the `selectfield`'s value array contains only the choosen entry's id.
  
  **Tags:** plugin-development, sections, elementtype
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-10. Score: 1 | Accepted answer
  
  Yes this is correct. The best documentation you can find is the source code, so looking at it is usually the way to go. Craft stores all relations with an **array** of element ids.
  
  When you have a `BaseRelationField` in your elements field layout you'll store the value - even if it's a single value - like
  
  ```
  $element->setFieldValue('day', [1]); //<- note, always pass an array
  
  ```
  
  (or the faster variant)
  
  ```
  $fieldsLocation = Craft::$app->getRequest()->getParam('fieldsLocation', 'fields');
  $element->setFieldValuesFromRequest($fieldsLocation);
  
  ```
  
  If you don't use a field layout and store your relations in a custom table/column you'll have to find a way that fits your requirements
  
  
  ---
  
  