public function Update400::requireDocumentMediaSourceField in Lightning Media 8.4
Makes the Document media type's source field required.
@update
Parameters
\Symfony\Component\Console\Style\StyleInterface $io: The I/O style.
File
- modules/
lightning_media_document/ src/ Update/ Update400.php, line 67
Class
- Update400
- Contains configuration updates targeting Lightning Media Document 4.0.0.
Namespace
Drupal\lightning_media_document\UpdateCode
public function requireDocumentMediaSourceField(StyleInterface $io) {
/** @var \Drupal\Core\Field\FieldConfigInterface $field */
$field = $this->fieldStorage
->load('media.document.field_document');
if ($field && $field
->isRequired() == FALSE) {
$question = (string) $this
->t('Do you want to make the @field field required on the @media_type media type?', [
'@field' => $field
->getLabel(),
'@media_type' => $this->mediaTypeStorage
->load('document')
->label(),
]);
if ($io
->confirm($question)) {
$field
->setRequired(TRUE);
$this->fieldStorage
->save($field);
}
}
}