Skip to content

Commit

Permalink
Update drupal.md
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagogomesverissimo authored Jul 2, 2024
1 parent fe7b2c3 commit 07a8686
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions docs/tutoriais/drupal.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,8 @@ Como chamar um script php usando linha de comando, útil, por exemplo, para cri

Carregando arquivo ao criar um node:

```bash

```php
use \Drupal\node\Entity\Node;
use \Drupal\file\Entity\File;

$data = file_get_contents('/home/thiago/arquivo.pdf');
$file = file_save_data($data, 'public://arquivo.pdf', FILE_EXISTS_REPLACE);
Expand All @@ -328,6 +326,33 @@ $node = Node::create([
$node->save();
```

Outra forma de carregar um arquivo:
```php
use \Drupal\node\Entity\Node;
use \Drupal\file\Entity\File;

$filepath = '/home/thiago/arquivo.pdf';
$file = File::create([
'filename' => basename($filepath),
'uri' => 'public://my-dir/' . basename($filepath),
'status' => 1,
'uid' => 1,
]);
$file->save();

$node = Node::create([
'type' => 'page',
'title' => 'Teste com arquivo',
'field_arquivo' => [
'target_id' => $file->id(),
'alt' => 'Pdf exemplo',
'title' => 'Pdf exemplo'
],
]);

$node->save();
```

Criação de uma submissão de um webform:

```bash
Expand All @@ -349,7 +374,6 @@ $webform_submission = WebformSubmission::create($values);
$webform_submission->save();
```


### Exercício 3

Neste exercício vamos trabalhar com o seguinte arquivo:
Expand Down

0 comments on commit 07a8686

Please sign in to comment.