You are here

function ContentExport::generateFile in Content Export YAML 8

Parameters

$directory String: location folder of exported entity

$filename String:

$content String: Yaml content

Return value

bool

1 call to ContentExport::generateFile()
ContentExport::exportBase in src/ContentExport.php

File

src/ContentExport.php, line 345

Class

ContentExport
Created by PhpStorm. User: USER Date: 11/13/18 Time: 2:04 PM

Namespace

Drupal\content_export_yaml

Code

function generateFile($directory, $filename, $content) {
  $fileSystem = \Drupal::service('file_system');
  if (!is_dir($directory)) {
    if ($fileSystem
      ->mkdir($directory, 0777, TRUE) === FALSE) {
      $this->logger
        ->error('Failed to create directory ' . $directory);
      \Drupal::messenger()
        ->addMessage(t('Failed to create directory ' . $directory), 'error');
      return FALSE;
    }
  }
  if (file_put_contents($directory . '/' . $filename . '.yml', $content) === FALSE) {
    \Drupal::messenger()
      ->addMessage(t('Failed to write file ' . $filename), 'error');
    $this->logger
      ->error('Failed to write file ' . $filename);
    return FALSE;
  }
  if (@chmod($directory . '/' . $filename . '.html.twig', 0777)) {
    \Drupal::messenger()
      ->addMessage(t('Failed to change permission file ' . $filename), 'error');
    $this->logger
      ->error('Failed to change permission file ' . $filename);
  }
  return TRUE;
}