You are here

public function OnlyOne::deleteContentTypeConfig in Allow a content type only once (Only One) 8

Delete the content type config variable.

Parameters

string $content_type: Content type machine name.

Return value

bool Return TRUE if the content type config was deleted or FALSE if not exists.

Overrides OnlyOneInterface::deleteContentTypeConfig

File

src/OnlyOne.php, line 149

Class

OnlyOne
Class OnlyOne.

Namespace

Drupal\onlyone

Code

public function deleteContentTypeConfig($content_type) {

  // Getting the config file.
  $config = $this->configFactory
    ->getEditable('onlyone.settings');

  // Getting the content types configured to have onlyone node.
  $onlyone_content_types = $config
    ->get('onlyone_node_types');

  // Checking if the config exists.
  $index = array_search($content_type, $onlyone_content_types);
  if ($index !== FALSE) {

    // Deleting the value from the array.
    unset($onlyone_content_types[$index]);

    // Saving the values in the config.
    $config
      ->set('onlyone_node_types', $onlyone_content_types)
      ->save();
    return TRUE;
  }
  return FALSE;
}