You are here

public function FieldMappings::submitForm in Schema.org configuration tool (RDF UI) 8

Overrides \Drupal\field_ui\FormDisplayOverview::submitForm().

Overrides FormInterface::submitForm

File

src/Form/FieldMappings.php, line 169

Class

FieldMappings
RDF UI Field Mapping form.

Namespace

Drupal\rdfui\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $form_values = $form_state
    ->getValue('fields');
  $mapping = rdf_get_mapping($this->entityTypeId, $this->bundle);

  // Add mapping for title field.
  if ($this->entityTypeId === 'node') {
    $type = $mapping
      ->getFieldMapping('title');
    if (empty($type)) {
      $mapping
        ->setFieldMapping('title', array(
        'properties' => array(
          'schema:name',
        ),
      ));
    }
  }
  foreach ($form_values as $key => $value) {
    $mapping
      ->setFieldMapping($key, array(
      'properties' => array(
        $value['rdf-predicate'],
      ),
    ));
  }
  $mapping
    ->save();
  $this
    ->messenger()
    ->addStatus($this
    ->t('Your settings have been saved.'));
}